SQL fieldtype changes when a query is modified to sort; GetData returns nothing
Posted: Tue Oct 31, 2017 9:47 pm
I posted this in comp.lang as well; this is the same with one addition:
I use the following code to read data from a MySQL database over ODBC
in my VO program:
oConn:=SQLConnection{"Myodbc",cDB,cpw}
cSQL:="SELECT somefield,text FROM Myview where Keyfield is null
oSelectView:=SQLSelect{ cSQL, oConn }
oSelectView:Gotop()
cField:="text"
cFieldType:=oSelectView:FIELDINFO( DBS_TYPE, cField)
cContent:=oServer:Getdata(cField) // Content of field 'text'
correctly assigned
This has always worked. The text field is of type 'text' and returns
"C" in the above FieldInfo statement.
Now my client wanted to insert the data in a specific order and asked
me to change the query as follows:
cSQL:="SELECT somefield,text FROM Myview where Keyfield is null ORDER
BY leadid ASC
So basically it only differs with this added:
ORDER BY leadid ASC
The result is quite strange. While GetData still retrieves the content
of MySQL varchar fields (like 'somefield' in the above query) this is
not the case for the text field anymore. The returned fieldtype
changed from "C" to "M" and the GetData now returns an empty content.
I emphasize that the query does not give a different result (e.g. if
executed in MySQL Workbench where we have one test view record
ready), also not in the VO program where the other fields return
content as before.
What could cause an ORDER BY addition to give this problem?
Addition: We replaced 'text' with CAST(tekst as CHAR(10000)) as tekst but this did not solve the problem.
Dick
I use the following code to read data from a MySQL database over ODBC
in my VO program:
oConn:=SQLConnection{"Myodbc",cDB,cpw}
cSQL:="SELECT somefield,text FROM Myview where Keyfield is null
oSelectView:=SQLSelect{ cSQL, oConn }
oSelectView:Gotop()
cField:="text"
cFieldType:=oSelectView:FIELDINFO( DBS_TYPE, cField)
cContent:=oServer:Getdata(cField) // Content of field 'text'
correctly assigned
This has always worked. The text field is of type 'text' and returns
"C" in the above FieldInfo statement.
Now my client wanted to insert the data in a specific order and asked
me to change the query as follows:
cSQL:="SELECT somefield,text FROM Myview where Keyfield is null ORDER
BY leadid ASC
So basically it only differs with this added:
ORDER BY leadid ASC
The result is quite strange. While GetData still retrieves the content
of MySQL varchar fields (like 'somefield' in the above query) this is
not the case for the text field anymore. The returned fieldtype
changed from "C" to "M" and the GetData now returns an empty content.
I emphasize that the query does not give a different result (e.g. if
executed in MySQL Workbench where we have one test view record
ready), also not in the VO program where the other fields return
content as before.
What could cause an ORDER BY addition to give this problem?
Addition: We replaced 'text' with CAST(tekst as CHAR(10000)) as tekst but this did not solve the problem.
Dick