# MySQL (ODBC) and PROP:SQL

**URL:** <https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899>\
**Category:** questions\
**Tags:** odbc, mysql\
**Created:** [January 5, 2024, 10:28am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899 "2024-01-05T10:28:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 5, 2024, 10:28am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/1 "2024-01-05T10:28:33Z")

</div>

Hello All,  
I have some SQL query but to make my question simple as possible, how to use something like this:

```auto
  sql_file{prop:sql} = 'SET @var := 10; '&|
                       'select @var;'

```

it give me error 90 (File system error, you have an error in your SQL syntax...)  
when I execute this directly on database, it works OK.  
Thanks.

---

<div class="post-metadata">

**Author:** ![ChristianB](https://clarionhub.com/user_avatar/clarionhub.com/christianb/32/4741_2.png) [@ChristianB](https://clarionhub.com/u/ChristianB)\
**Post date:** [January 5, 2024, 11:25am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/2 "2024-01-05T11:25:12Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 5, 2024, 11:36am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/3 "2024-01-05T11:36:37Z")

</div>

Hello, syntax “:=” is OK.  
Now I found that this works:

```auto
  sql_file{prop:sql} = 'SET @var := 10;'
  sql_file{prop:sql} = 'select @var;'
  next(sql_file)
  message(sql:f1) <- it give me 10, which is OK.

```

with other words, using 2 “prop:sql” instead of 1.

---

<div class="post-metadata">

**Author:** ![JonW](https://clarionhub.com/user_avatar/clarionhub.com/jonw/32/1344_2.png) [@JonW](https://clarionhub.com/u/JonW)\
**Post date:** [January 5, 2024, 12:30pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/4 "2024-01-05T12:30:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [January 5, 2024, 3:32pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/5 "2024-01-05T15:32:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JonW](https://clarionhub.com/user_avatar/clarionhub.com/jonw/32/1344_2.png) [@JonW](https://clarionhub.com/u/JonW)\
**Post date:** [January 5, 2024, 4:24pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/6 "2024-01-05T16:24:59Z")

</div>

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’

and

x{PROP:SQL} = ‘CALL customers\_in\_town(\<39\>’ & sometown & ‘\<39\>)’

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.

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [January 5, 2024, 11:19pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/7 "2024-01-05T23:19:01Z")

</div>

You might be right.  
I’m guessing the real statements are more involved.

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 6, 2024, 9:28am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/8 "2024-01-06T09:28:13Z")

</div>

Here is code I try to call:

```auto
sql_file{prop:sql} = 'SET @myorder := 0; '&|
                     'UPDATE my_table '&|
                     'SET myorder = (@myorder := @myorder + 1) '&|
                     'WHERE some_id = 3 AND other_id = 1 '&|
                     'ORDER BY myorder;'

```

but it does not work (error 90).  
It looks like setting (and clearing) variable @myorder and then calling SQL works, so I’m using now:

```auto
sql_file{prop:sql} = 'SET @myorder := 0;'
sql_file{prop:sql} = 'UPDATE my_table '&|
                     'SET myorder = (@myorder := @myorder + 1) '&|
                     'WHERE some_id = 3 AND other_id = 1 '&|
                     'ORDER BY myorder;'

```

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.

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 6, 2024, 9:37am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/9 "2024-01-06T09:37:28Z")

</div>

> [@JonW](#):
>
> PROP:SQLRowSet

It does not work, too. It also give me error 90.

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [January 6, 2024, 11:23am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/10 "2024-01-06T11:23:53Z")

</div>

> 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).

Oh. ok. What you want is a window function. Have a look at Row\_Number()

e class="onebox allowlistedgeneric" data-onebox-src="https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function\_row-number"\> ![](https://labs.mysql.com/common/themes/sakila/favicon.ico)[dev.mysql.com](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_row-number)

### [MySQL :: MySQL 8.4 Reference Manual :: 14.20.1 Window Function Descriptions](https://dev.mysql.com/doc/refman/8.0/en/window-function-descriptions.html#function_row-number)

You can issue the statement to renumber the lines of the order in question. You don’t really need to just go from where you are now.

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [January 6, 2024, 1:49pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/11 "2024-01-06T13:49:49Z")

</div>

> [@seanh](#):
>
> Oh. ok. What you want is a window function. Have a look at Row\_Number()

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?

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [January 6, 2024, 11:38pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/12 "2024-01-06T23:38:42Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 7, 2024, 6:30am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/13 "2024-01-07T06:30:41Z")

</div>

Thank you for your idea.

---

<div class="post-metadata">

**Author:** ![JohnM](https://clarionhub.com/user_avatar/clarionhub.com/johnm/32/6203_2.png) [@JohnM](https://clarionhub.com/u/JohnM)\
**Post date:** [January 8, 2024, 9:23am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/14 "2024-01-08T09:23:35Z")

</div>

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 …

eg:

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/d/d42c8dcbf7265ad756f798dc984e94ea9c82204e.png)

---

<div class="post-metadata">

**Author:** ![JonW](https://clarionhub.com/user_avatar/clarionhub.com/jonw/32/1344_2.png) [@JonW](https://clarionhub.com/u/JonW)\
**Post date:** [January 8, 2024, 12:52pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/15 "2024-01-08T12:52:19Z")

</div>

A couple (well, four) of things.

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.

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 9, 2024, 8:26am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/16 "2024-01-09T08:26:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 9, 2024, 8:43am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/17 "2024-01-09T08:43:56Z")

</div>

Thank you for all your suggestions, I re-read Sean’s suggestion (row\_number()) after your post and it looks like great solution.  
However, I also try with the BEGIN.. END like described here: [MySQL :: MySQL 8.0 Reference Manual :: 13.6.1 BEGIN … END Compound Statement](https://dev.mysql.com/doc/refman/8.0/en/begin-end.html) and here: [MySQL BEGIN … END Compound Statement (tutorialspoint.com)](https://www.tutorialspoint.com/mysql/mysql_begin_end_compound.htm)  
but it does not worked. It looks like it is designed for stored procedures and I do not use them (I use simple SQL query).  
Thanks anyway.

---

<div class="post-metadata">

**Author:** ![JonW](https://clarionhub.com/user_avatar/clarionhub.com/jonw/32/1344_2.png) [@JonW](https://clarionhub.com/u/JonW)\
**Post date:** [January 9, 2024, 5:44pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/18 "2024-01-09T17:44:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Daniel1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daniel1](https://clarionhub.com/u/Daniel1)\
**Post date:** [January 10, 2024, 8:54am UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/19 "2024-01-10T08:54:38Z")

</div>

Thanks but it does not work with MySQL ODBC, except third one.  
Code I used on MSSQL works fine:

```auto
  sql_file{prop:sql} = 'DECLARE @myorder as int; '&|
                       'SET @myorder = 0 ; '&|
                       'UPDATE mytable SET @myorder = myorderOther = @myorder + 1 '&|
                       'WHERE mytable.id = 123'

```

but for MySQL not.  
I also try to combine BEGIN .. END but it does not worked, too.  
Like said, I will use row\_number(), it works fine.  
Thanks anyway.

---

<div class="post-metadata">

**Author:** ![Rick\_UpperPark](https://clarionhub.com/user_avatar/clarionhub.com/rick_upperpark/32/346_2.png) [@Rick\_UpperPark](https://clarionhub.com/u/Rick_UpperPark)\
**Post date:** [January 10, 2024, 2:53pm UTC](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899/20 "2024-01-10T14:53:23Z")

</div>

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.

[Next page](https://clarionhub.com/t/mysql-odbc-and-prop-sql/6899.md?page=2)
