Вопрос

I am going through all the records in the column vals of the Values table and tranforming any absolute urls to relative urls. I get this error

[Macromedia][SQLServer JDBC Driver][SQLServer]Incorrect syntax near '='.

On the 3rd to last line of this block of code:

<cfquery name="getVals" datasource="#dataBase#">
  Select vals
  FROM Values
</cfquery>

<cfloop 
  query = "getVals">

  <cfset val=#vals#>
    <cfset valEdited= REReplace(
      val, 
      '"(https?:\/\/)?(www\.)?(example\.com)(\/)?"', 
      "'index.php'", 
      'ALL'
      )>

    <cfquery name="update" datasource="#dataBase#">
      UPDATE   Values
      SET      vals = <cfqueryPARAM value = #valEdited#>
      WHERE    ID = <cfqueryPARAM value = #getVals.currentRow#>
    </cfquery>
</cfloop>

Any ideas on how to fix it?

Это было полезно?

Решение

The first thing I would look at is you have a semi colon at the end of the CFSET for ValEdited. That will blow up first.

Then check your code, to see if it gives you the same error.

A best practice you might want to consider, is only use # when you are outputting values... so

<cfset val = getVals.vals> 

is sufficient.

The next thing I would look at is you where statement. This assumes all of your values have ID, 1 to the number of records in the table. If this is not so, you might have to update this to

where ID = #getVals.ID#

Hope this helps. By the time I wrote it up, everyone else pretty much said the same thing :P

Другие советы

personally I wouldn't be updating the values of the column of the query directly. To me that makes it confusing of exactly what's going on. The approach that I always do is to just add another column to the query using QueryAddColumn().

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_m-r_16.html

This allows you to not only have the changes you need available in the query as a new column, but also leaves the original column alone so you can debug easier. To add the new column just do:

<cfquery name="getVals" datasource="#dataBase#">
  Select vals
  FROM Values
  order by id
</cfquery>

<cfset newVals = []>

<cfloop query="getVals">

    <cfset temp = REReplace(
      val, 
      '"(https?:\/\/)?(www\.)?(example\.com)(\/)?"', 
      "'index.php'", 
      'ALL'
      )>

    <cfset ArrayAppend(newVals, temp)>

</cfloop>

<cfset QueryAddColumn(getVals, "newVals", "Varchar", newVals)>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top