Hello, I can see this is MySQL, but perhaps the problem is the " := " syntax from the Clarion side? I would’ve used ‘set @var = 10;’ etc …you have, ofcourse declared @var as well?
Also, even without the Error 90, your original code would not have worked. Clarion assumes that any PROP:SQL that does not start with SELECT is not going to try and return any information back to Clarion, so it doesn’t bother telling the ODBC layer “and this is where I want you to put the information returned” (the file buffer). If you want to get info back from a PROP:SQL that does not start with “SELECT” you need to use PROP:SQLRowSet
Can you create a stored procedure that does what you need and returns the results via select? Then just all the stored proc from Clarion with prop:sql.
Hard to know what they are really trying to do, but if they are just trying to get a result set limited by a variable they set beforehand, then there’s not a lot of difference between an approach like:
x{PROP:SQL} = 'set @town = ’ &sometown
x{PROP:SQL} = ‘select customers from v_customer where town = @town’
except for you have to create the stored procedure on the server first which returns the resultset from v_customer. So for simple stuff the first approach might be easier.
and it looks OK.
If there is some better code for this, I would like to know.
Basically, I need to renumber “myorder” values, when they looks like 1,2,4 etc. (and need 1,2,3).
It happends when I delete some record etc.
Thanks.
If there is some better code for this, I would like to know.
Basically, I need to renumber “myorder” values, when they looks like 1,2,4 etc. (and need 1,2,3).
At what point does one give up on providing everything SQL through Clarion and easily create exactly what is needed on the backend for one straight forward call?
At what point does one give up on providing everything SQL through Clarion and easily create exactly what is needed on the backend for one straight forward call?
Hard to say. I tend to create a lot of functions/stored procedures on the backend that I call to do stuff (I use PostgreSQL)
I think your SQL will be something like this:
WITH tord AS (
SELECT
ord_Number,
ord_line,
ROW_NUMBER() OVER (
PARTITION BY ord_Line
ORDER BY
ord_line
) new_num
FROM
orderLines
)
UPDATE OrderLines
SET ord_line = new_num
FROM tord
WHERE
tord.ord_number = orderlines.number AND
tord.ord_line = orderlines.number AND
orderlines.order = somevalue;
You just need to put the order number in somevalue. This will renumber to whole order.
Another way to do it (rather than embedding SQL statements in strings that cannot be checked by the compiler !) would be to use Clarion’s IDE to provide the equivalent of SELECT filters, ORDER BY parameters, etc, etc …
First, I wasn’t suggesting PROP:SQLRowset would solve your invalid SQL error, I was pointing out that even if your SQL was valid, you would have to use PROP:SQLRowset to get clarion to retrieve the value.
Second, like Sean, I would use row_number().
Third, I wouldn’t normally ever bother modifying a sequence number like that in the data. I’d leave the numbers as they are, and if the user wanted to see consecutive numbers I would show them a view that used (for example) row_number() over (partition by some_id,other_id order by myorder).
Fourth, I think you need to read the little section on “Compound Statement syntax” in the MySQL manual. Compound statements have to be enclosed in a BEGIN…END: block. I’m not sure what would happen with your original query (you have a select without an into), but if you wanted to do your set followed by an update, that would have to be enclosed in begin…end; Once you have it enclosed within begin…end it should be a valid (compound) sql statement.
Thanks, but I do not use a browse or queue or anything like that.
That project is all source except one (main) window without anything related to my problem.
Thanks anyway.
Works for me using Oracle, which has more or less the same syntax.
With a little program like this:
PROGRAM
CODE_TABLE FILE,DRIVER(‘ODBC’),OWNER(‘ora,testjon’),NAME(‘TESTJON.“CODE_TABLE”’),PRE(COD)
record RECORD
CT_TYPE_TABLE CSTRING(27),NAME(‘“CT_TYPE_TABLE”’)
CT_DESCRIPTION CSTRING(31),NAME(‘“CT_DESCRIPTION”’)
CT_ASSOCIATED_TABLE CSTRING(3),NAME(‘“CT_ASSOCIATED_TABLE”’)
CT_VALUE CSTRING(5),NAME(‘“CT_VALUE”’)
CT_CODETABLE_ID SHORT,NAME(‘“CT_CODETABLE_ID”’)
END
END
MAP
END
CODE
open(code_table)
code_table{PROP:SQL} = ‘declare some_value number(2); begin some_value := 42; insert into code_table values(’‘1’‘,’‘2’‘,’‘3’‘,’‘4’‘,199); end;’
if error() then message(‘Take 1 ’ & error() & fileerror()).
code_table{PROP:SQL} = ‘insert into code_table values(’‘1’’,‘‘2’’,‘‘3’’,‘‘4’’,199);insert into code_table values(‘‘1’’,‘‘2’’,‘‘3’’,‘‘4’’,399); ’
if error() then message(‘Take 2 ’ & error() & fileerror()).
code_table{PROP:SQL} = ‘insert into code_table values(’‘1’’,‘‘2’’,‘‘3’’,‘‘4’’,199)’
if error() then message('Take 3 ’ & error() & fileerror()).
Only Take 2 (which has the two statements not in a PL/SQL block) raises an error. The first statement, with the declare and the begin…end anonymous block, works fine. Take 3, which has a single sql statement works fine.
I’m curious why you don’t want to use stored procedures.
Using them would eliminate all of these oddities of using prop:sql for multiple statement batches.