SQL error code = -502

208 views
Skip to first unread message

Luis Lince

unread,
Mar 22, 2023, 11:25:17 AM3/22/23
to firebird-support
Hello, I have an error that appears randomly, sometimes it appears sometimes not, I have never had this error in this way, the version of firebird is version 3.0.10.33601-0_x64 and the strangest thing is that when it sends me the message error The cursor name is incomplete:

SQL error code = -502
Invalid cursor declaration
Statement already has a cursor CURSOR_TOWNSEND assigned

The names of the cursors in this case, I format as follows:

cursor.Format("cursor_%s_%d_isAttach", (LPCTSTR)userLogged, collegeid);

In the error, the cursor name does not have the second underscore or the rest.

Someone in his great wisdom, will have an idea.

Dimitry Sibiryakov

unread,
Mar 22, 2023, 11:29:49 AM3/22/23
to firebird...@googlegroups.com
Luis Lince wrote 22.03.2023 16:25:
> Someone in his great wisdom, will have an idea.

Named cursors are next to useless feature. Are you sure that you use it
correctly and for any practical purpose? The simplest solution would be stop
using them completely.
If you want to find out where the error comes from you can use Firebird Audit
service which will show you connection and transaction details. Then you should
be able to trace it back to exact application query.

--
WBR, SD.

Luis Lince

unread,
Mar 22, 2023, 11:49:50 AM3/22/23
to firebird...@googlegroups.com
If I don't use them, firebird throws me this error:
SQL error code = -504
Invalid cursor reference
Cursor is not open

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-support/89208b8f-b5c7-65f4-9787-648b53f79cd6%40ibphoenix.com.

Dimitry Sibiryakov

unread,
Mar 22, 2023, 11:52:25 AM3/22/23
to firebird...@googlegroups.com
Luis Lince wrote 22.03.2023 16:49:
> If I don't use them, firebird throws me this error:
> SQL error code = -504
> Invalid cursor reference
> Cursor is not open

This error is not related to cursor names. Unnamed cursors are fine. You must
open result set before fetching (or don't fetch after closing).

--
WBR, SD.

Luis Lince

unread,
Mar 22, 2023, 1:53:24 PM3/22/23
to firebird...@googlegroups.com
So from what you tell me: there is no need to call isc_dsql_set_cursor_name because named cursors is a useless feature.

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.

Mark Rotteveel

unread,
Mar 22, 2023, 3:55:54 PM3/22/23
to firebird...@googlegroups.com
On 22-03-2023 16:29, 'Dimitry Sibiryakov' via firebird-support wrote:
> Luis Lince wrote 22.03.2023 16:25:
>> Someone in his great wisdom, will have an idea.
>
>   Named cursors are next to useless feature. Are you sure that you use
> it correctly and for any practical purpose? The simplest solution would
> be stop using them completely.

That is a bit of a mischaracterization and hyperbole. You have to use a
named cursor if you want to do positioned updates.

Mark
--
Mark Rotteveel

Dimitry Sibiryakov

unread,
Mar 22, 2023, 4:12:42 PM3/22/23
to firebird...@googlegroups.com
Luis Lince wrote 22.03.2023 18:53:
> So from what you tell me: there is no need to call isc_dsql_set_cursor_name
> because named cursors is a useless feature.

Yes, exactly.

Mark Rotteveel wrote 22.03.2023 20:55:
> That is a bit of a mischaracterization and hyperbole. You have to use a named
> cursor if you want to do positioned updates.

Yes, but in this case you have to issue explicit SELECT FOR UPDATE statement
and it is simpler to add AS CURSOR to it rather than use another API call.
And without FOR UPDATE you'll get cursor position desync that indeed make
positioned updates useless.

--
WBR, SD.

Luis Lince

unread,
Mar 22, 2023, 4:32:52 PM3/22/23
to firebird...@googlegroups.com
I thank you for the information and I go back and ask you to see if you give me clues: Why is the error random? Sometimes it appears sometimes not, there are thousands of daily transactions and it only appears a few times, and the strangest thing is that when it sends me the message error the cursor name is incomplete.

Thanks for your help.

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.

Dimitry Sibiryakov

unread,
Mar 22, 2023, 4:51:06 PM3/22/23
to firebird...@googlegroups.com
Luis Lince wrote 22.03.2023 21:32:
> I thank you for the information and I go back and ask you to see if you give me
> clues: Why is the error random? Sometimes it appears sometimes not, there are
> thousands of daily transactions and it only appears a few times, and the
> strangest thing is that when it sends me the message error the cursor name is
> incomplete.

My best bet that execution flow of your application is not determined and two
queries with the same AS CURSOR clause may be executed in the same attachment
depending on user interaction.

--
WBR, SD.

Luis Lince

unread,
Mar 22, 2023, 5:35:55 PM3/22/23
to firebird...@googlegroups.com
Please correct me if I'm wrong, but I just did a query to one of my tables to determine the cause of the unqualified cursor name error, and I find that there is a white space that is getting through, but it's getting through because when I do this database query:
select uid from students where lower(uid)='gthmkl   ' matches me, just like this:
select uid from students where lower(uid)='gthmkl'
Tell me if I'm wrong about something as basic as this or am I missing something due to my lack of sleep.

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.

Luis Lince

unread,
Mar 22, 2023, 6:09:35 PM3/22/23
to firebird...@googlegroups.com
SQL standard!!!! what crap!!!

Mark Rotteveel

unread,
Mar 23, 2023, 3:43:17 AM3/23/23
to firebird...@googlegroups.com
On 22-03-2023 21:12, 'Dimitry Sibiryakov' via firebird-support wrote:
> Mark Rotteveel wrote 22.03.2023 20:55:
> > That is a bit of a mischaracterization and hyperbole. You have to use
> a named
> > cursor if you want to do positioned updates.
>
>   Yes, but in this case you have to issue explicit SELECT FOR UPDATE
> statement and it is simpler to add AS CURSOR to it rather than use
> another API call.
>   And without FOR UPDATE you'll get cursor position desync that indeed
> make positioned updates useless.

As far as I'm aware, AS CURSOR is a PSQL feature, not a DSQL feature.

Mark
--
Mark Rotteveel

Mark Rotteveel

unread,
Mar 23, 2023, 3:45:21 AM3/23/23
to firebird...@googlegroups.com
On 22-03-2023 22:35, Luis Lince wrote:
> Please correct me if I'm wrong, but I just did a query to one of my
> tables to determine the cause of the unqualified cursor name error, and
> I find that there is a white space that is getting through, but it's
> getting through because when I do this database query:
> select uid from students where lower(uid)='gthmkl   ' matches me, just
> like this:
> select uid from students where lower(uid)='gthmkl'
> Tell me if I'm wrong about something as basic as this or am I missing
> something due to my lack of sleep.

That is SQL standard string comparison: trailing spaces are considered
insignificant (at least in the normal collations).

Mark
--
Mark Rotteveel

Dimitry Sibiryakov

unread,
Mar 23, 2023, 6:47:24 AM3/23/23
to firebird...@googlegroups.com
Mark Rotteveel wrote 23.03.2023 8:43:
>>    Yes, but in this case you have to issue explicit SELECT FOR UPDATE
>> statement and it is simpler to add AS CURSOR to it rather than use another API
>> call.
>>    And without FOR UPDATE you'll get cursor position desync that indeed make
>> positioned updates useless.
>
> As far as I'm aware, AS CURSOR is a PSQL feature, not a DSQL feature.

Indeed. I'm sorry, I was wrong.
Also IIRC JDBC specs supports updatable result set so if topic starter uses
Jaybird and this feature, the errors that he got become more understandable.

--
WBR, SD.

Mark Rotteveel

unread,
Mar 23, 2023, 10:56:48 AM3/23/23
to firebird...@googlegroups.com
The code the OP showed in the topic start looks more like C or C++ to me
(given the cast to LPCTSTR).
--
Mark Rotteveel

Luis Lince

unread,
Mar 23, 2023, 1:38:32 PM3/23/23
to firebird...@googlegroups.com
The cursor error -502 was caused by the cursor name having a white space and that caused firebird to truncate the cursor name where the white space started, the following characters that firebird did not use as the cursor name, were what that differentiated the name of the cursor from another and therefore the error. However something changed in version 3.010 of firebird in one of two respects. Because that behavior must have been going on for a long time on my system. But it is now that I updated to version 3.010 (before I had 3.07) that this is presented. What could have changed in firebird:
1. That now it does comply strictly in the comparison of strings with the SQL standard and the white spaces at the end are irrelevant.
2. Or now firebird doesn't like whitespace in cursor names.

I already fixed the problem. Preventing white space from reaching the cursor naming mechanism.

And that's right, it's C++

Anyway, thanks for the help. The desire to collaborate that exists on the Internet never ceases to impress me. Thank you very much again.

--
You received this message because you are subscribed to the Google Groups "firebird-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-suppo...@googlegroups.com.

Dimitry Sibiryakov

unread,
Mar 23, 2023, 4:08:38 PM3/23/23
to firebird...@googlegroups.com
Luis Lince wrote 23.03.2023 18:38:
> The cursor error -502 was caused by the cursor name having a white space and
> that caused firebird to truncate the cursor name where the white space started,
> the following characters that firebird did not use as the cursor name

I would call it a bug. Please, fill issue in github tracker and provide a
testcase if you don't mind.

--
WBR, SD.
Reply all
Reply to author
Forward
0 new messages