ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SQLite3 Copy row to different Table ? Help

Solved!
Go to solution

Hi all.

 

I am trying to copy an entire row from one table and copy it into another table.

This is what i currently got.

 

 

Insert into Table2 select * from Table2 where ROWID = 1;

 

But i keep on getting a General Protection error by the following SQLitefunction which is found in the sqlite3.c file

 

/*
** Report the allocated size of a prior return from xMalloc()
** or xRealloc().
*/
static int sqlite3MemSize(void *pPrior){
  sqlite3_int64 *p;
  if( pPrior==0 ) return 0;
  p = (sqlite3_int64*)pPrior;
  p--;
  return (int)p[0];
}

 

Can Someone please help me solve this problem ?

 

Help share your knowlegde
0 Kudos
Message 1 of 18
(8,344 Views)

did you compile the sqlite3 library yourself using CVI or are you using a precompiled library ? if you compiled it yourself, have a look at the code for the xMalloc function, and see if the size of the block is really stored in the 64 bit integer just preceding the allocated block (the implementation of malloc() is undefined, thus not all C runtime stores the size of the block at this place)

 

also, it seems to be a typo but your SQL query is wrong: you are trying to insert into the same table than you selected from. although this should not end with a general protection fault.

0 Kudos
Message 2 of 18
(8,338 Views)

sorry for the late reply.

 

I did make a mistake with the coding

it was meant to be :

 

insert into Table2 values (select * from Table1 where ROWID = 1);

 

The General Protection error is gone but this statement doesnt seem to work.

Help share your knowlegde
0 Kudos
Message 3 of 18
(8,316 Views)

don't you have a column declared as a primary key on those tables ? then you may have a collision between the key of the record you read from table1 and an existing record in table2 (i don't remember if sqlite3 enforces primary key constaints). also, i assume you made sure the 2 tables have the same schema. also check that table2 does not have a trigger on insert which would drop the data you wish to insert.

 

(anyway, the general protection fault you had at first does not seem right. you may have to report a bug to the developper of sqlite).

Message Edited by dummy_decoy on 08-28-2009 04:49 AM
0 Kudos
Message 4 of 18
(8,314 Views)

You were right it was the primary keys that were clashing.

Thanks for that.

But i got an even bigger problem.

Hopefully you can help me.

 

A little background of my app :

My program reads in infomation from a txt file and stores it into the SQLite database.

Then it reads the database and creates a tree with that info.

This is all done One row at a time, So i read from txt,add to database,add to tree,then start the process again.

The Database is made up of only Temp Tables.

 

After about 22 rows i cant read from the database and i dont know how to fix this.

I even tried waiting.

 

 

Help share your knowlegde
0 Kudos
Message 5 of 18
(8,307 Views)

welll, 22 rows is not much, especially for a database...

 

which function are you using to read from the database: sqlite3_exec() or the long way through sqlite3_prepare_v2() sqlite3_step() and sqlite3_finalize() ?

what error message or error code does the read returns ?

are you sure you free everything that you do not need anymore (finalizing statements, freeing returned error messages, ...) ? did you make sure you are not in a transaction (nested transactions were not supported on older version of sqlite) ?

0 Kudos
Message 6 of 18
(8,303 Views)

Im using the 3 step Method.

The wierd thing is that it used to work i just dont know why its not now.

Im not using transactions and the Query function is all ways finalized.

I dont get any errors and thats the wierd thing because if there was i would then know what is the problem.

 

Help share your knowlegde
0 Kudos
Message 7 of 18
(8,299 Views)

I forgot to mention that only inserts work.

I think that some how there is a write only lock occuring althought there is to Error/Message indicating so.

Help share your knowlegde
0 Kudos
Message 8 of 18
(8,296 Views)
as i don't have any other idea, can you please strip down your code to its simplest form and post it here so that we can try to reproduce the problem ?
0 Kudos
Message 9 of 18
(8,259 Views)

Sorry for the late reply i had a problem with me internet.

Its abit hard to simplify the function cause there is quit abit.

But i have narrowed the problem down.

I dont a Data Integrity check and i got this error : 

 

"*** in database main *** \n Corruption detected in cell 0 on page 2 \n Fragmentation of 5 bytes reported as 0 on page 2"

 

So the problem was not databse locking but when i try to read from it the info was all weird.

Is the any suggestions you can give ?

Help share your knowlegde
0 Kudos
Message 10 of 18
(8,218 Views)