ni.com is currently undergoing scheduled maintenance.
Some services may be unavailable at this time. Please contact us for help or try again later.
08-27-2009 05:03 AM
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 ?
Solved! Go to Solution.
08-27-2009 07:27 AM
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.
08-28-2009 04:38 AM
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.
08-28-2009 04:47 AM - edited 08-28-2009 04:49 AM
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).
08-28-2009 05:08 AM
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.
08-28-2009 05:32 AM
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) ?
08-28-2009 05:57 AM
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.
08-28-2009 06:18 AM
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.
08-29-2009 02:01 AM
09-01-2009 01:17 AM
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 ?