NexusDB Newsgroups

NexusDB Newsgroups (http://www.nexusdb.com/forums/index.php)
-   nexusdb.public.support.cbuilder (http://www.nexusdb.com/forums/forumdisplay.php?f=27)
-   -   INSERT INTO add each record twice (http://www.nexusdb.com/forums/showthread.php?t=18848)

kts 2nd December 2014 06:27 AM

INSERT INTO add each record twice
 
Hi,

I am using INSERT INTO from TnxQuery to copy from one table to another. The result always add each record twice. When I execute the exact same SQL INSERT INTO queries from Nexus DB Enterprise Manager(on the same tables created from code), it works without adding the records twice. Is this a bug, or is it my setup of the nexus components that is wrong..?

I avoided the problem for some time by replacing the following query:

Code:

INSERT INTO DestTable SELECT * FROM SrcTable
with:
Code:

INSERT INTO DestTable SELECT * FROM SrcTable t1 WHERE NOT EXISTS(SELECT ID FROM DestTable t2 WHERE t2.ID = t1.aID)
But now I need more advance INSERT INTO queries and cannot do this to avoid the problem.

I am using NexusDB: 4,0006 Release (C20) 32bit on RAD Studio XE6 (C++), Windows 8.1.

Rodrigo Gomez [NDX] 2nd December 2014 07:54 AM

Re: INSERT INTO add each record twice
 
Without seeing the actual code that does the work, it's impossible to know if there is
something wrong with it.

As you said, running the query within EM works fine, so one could assume the SQL script is
working fine, but that's the only thing that you posted ;)

--
Rodrigo Gómez [NDX]
México, GMT-6

Thorsten Engler [NDA] 2nd December 2014 09:19 AM

Re: INSERT INTO add each record twice
 
I'm pretty sure that there is nothing wrong with the server that makes it copy
every record twice, much more likely is that you are doing something on the
client side which results in the query being send to the server for execution
twice.

e.g. you might have the "ActiveRuntime" property on the query set to true,
which results in the query being executed the first time when the containing
form/data module is created, and then you are calling Execute or Open on the
query object again later.

Or other such issues.

kts wrote:

>
> Hi,
>
> I am using INSERT INTO from TnxQuery to copy from one table to another.
> The result always add each record twice. When I execute the exact same
> SQL INSERT INTO queries from Nexus DB Enterprise Manager(on the same
> tables created from code), it works without adding the records twice. Is
> this a bug, or is it my setup of the nexus components that is wrong..?
>
> I avoided the problem for some time by replacing the following query:
>
>
> Code:
> --------------------
> INSERT INTO DestTable SELECT * FROM SrcTable
> --------------------
>
> with:
>
> Code:
> --------------------
> INSERT INTO DestTable SELECT * FROM SrcTable t1 WHERE NOT EXISTS(SELECT
> ID FROM DestTable t2 WHERE t2.ID = t1.aID) --------------------
>
>
> But now I need more advance INSERT INTO queries and cannot do this to
> avoid the problem.
>
> I am using NexusDB: 4,0006 Release (C20) 32bit on RAD Studio XE6 (C++),
> Windows 8.1.



kts 2nd December 2014 09:41 AM

Problem found with my code
 
I was running both ExecSQL and Open on the TnxQuery. Sorry for this mistake, I should have seen this.

Thanks for both of your answers, and sorry for the inconvenience.

Thorsten Engler [NDA] 2nd December 2014 10:51 AM

Re: INSERT INTO add each record twice
 
No worries, glad you found it.

kts wrote:

>
> I was running both ExecSQL and Open on the TnxQuery. Sorry for this
> mistake, I should have seen this.
>
> Thanks for both of your answers, and sorry for the inconvenience.




All times are GMT +11. The time now is 09:38 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.