Gerry Snyder ha scritto:
Luca Moratto wrote:

Thanks Gerry,

but I can Create my table in memory from an attached db, I can Insert new rows and I can Select the new rows and all values are correct, except for my key field that is 0.
My Insert statement is INSERT INTO myTable VALUES (?,?,?);
I prepare this statement with sqlite3_prepare
I bind all values with sqlite3_bind_int, sqlite3_bind_text, ...
I bind my key field with sqlite3_bind_null
I exec with sqlite3_step

It works because if I exec e SELECT rowid,* FROM myTable I can find all the new rows and all values except for my key field (INTEGER PRIMARY KEY, I have tried also AUTOINCREMENT) that is 0, but rowid is correct....

I need to use a SELECT *, I can't get rowId so how and when my key field has the same value of rowId, why it does't works?

Thanks in advanced
Luke

Luke,

Sorry, I should not have even mentioned that part, since it obviously worked for you and it detracted from my main point, which you missed.

When you create the table in the :memory: file by using
CREATE TABLE AS, the PRIMARY KEY part of the field description gets dropped. Reread the last part of the example I posted. Or run
select sql from sqlite_master
yourself with the rest of your code.

You have to create the :memory: copy of the table with a different method. I would suggest using the other format of the CREATE TABLE command and populating it with data from a SELECT.

Gerry



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Thanks Gerry and excuse me, I had not read your answer well.

I have change my application:
now first I read sql statements from attachedDb.sqlite_master where type='table';
then exec that sql to create tables,
then I exec INSERT INTO 'mynewtable' AS SELECT * FROM 'attachedDb'.'mytable'.
And now primary key works as expected!
I already created all the indexes after table creation, but I believed that the constraint of primary key came copied also by "create table ... as ...)...

Thanks
Luke


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to