[sqlite] Problem inserting empty Foreign Key in c++
Hi, I'm having problem inserting one record into a table that has Foreign Key constraint, whereas I can succeed with the same SQL statement in command line to the same table. Though I found I can bypass this problem by not including the FK in my c++ code at all. I'd still like to know the reason. My SQL statement in c++ before being prepared is as below: Insert into sometable (name,l_id,_id,mxrp,status,cnt,ts,metadata,slug,ctype,FK_id,cdate) VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12) And the real statement after passed the prepare API is like this: INSERT INTO sometable (name,l_id,_id,mxrp,status,cnt,ts,metadata,slug,ctype,FK_id,cdate) VALUES ('test','','c05f1e6f37bd8641b7d18892','13000','','0','1311744399','','','2','','Wed Jul 27 12:06:02 CST 2011'); And the above statement worked well in command line for me to the same table, but failed with the error message of "constraint failed" from sqlite_errmsg(). Also that I don't have the constraint of NOT NULL in my FK_id column, which means that the value of empty string to the column of FK_id should not cause problem as how it acted in command line. Plus I'm using the _v2 version of APIs to open connection and prepare statement. Any idea is very appreciated in advance. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] sqlite-users Digest, Vol 44, Issue 4
> > -- > > Message: 4 > Date: Wed, 3 Aug 2011 16:25:13 +0200 > From: Stephan Beal > Subject: Re: [sqlite] Deep copy of 2 sqlite3*? > To: General Discussion of SQLite Database > Message-ID: > > > Content-Type: text/plain; charset=ISO-8859-1 > > On Wed, Aug 3, 2011 at 12:56 PM, Teg wrote: > > > I'd suggest either not doing it (prevent the copy constructor from > > compiling by declaring it private) or doing it by passing ownership of > > the connection around as if it was a socket or file handle. > > > > +1 to that. > > It is "almost never" a good idea to implement copy ctors for classes which > refer to stream handles and such. > > The absolute simplest/sanest/safest way to implement this is to declare the > copy ctor and copy assignment operator as private and NOT implement them. > > -- > - stephan beal > http://wanderinghorse.net/home/stephan/ > > > -- > > > -- > > Message: 6 > Date: Wed, 3 Aug 2011 17:17:24 +0200 > From: Stephan Beal > Subject: Re: [sqlite] Deep copy of 2 sqlite3*? > To: General Discussion of SQLite Database > Message-ID: > > > Content-Type: text/plain; charset=ISO-8859-1 > > On Wed, Aug 3, 2011 at 4:20 AM, Nikki Tan wrote: > > > Hi sqlite-users! > >It's just that I'm writing a copy constructor of my own mini sqlite > > wrapper, and I ended up having to do a deep copy of a sqlite3* points to > a > > SQLite connection. And I'm just wondering is it okay that I just do it > with > > memcpy(), by digging into the code for the definition of struct sqlite3 > > and > > count the total bytes of this struct? > > > > > Another point: memcpy() will NOT do what you want here because the sqlite3 > structure dynamically allocates OTHER structures and points to them. A > memcpy() will copy the pointers but not their contents. i.e. you'll have 2 > copies of an sqlite3 handle which both point to (and own!) the underying > memory. > > NEVER use memcpy() to copy non-trivial types (e.g. those which contain > owned > pointers). > > -- > - stephan beal > http://wanderinghorse.net/home/stephan/ > > >Yes and indeed to "Another point:", thanks for all the suggestions!! ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Deep copy of 2 sqlite3*?
Hi sqlite-users! It's just that I'm writing a copy constructor of my own mini sqlite wrapper, and I ended up having to do a deep copy of a sqlite3* points to a SQLite connection. And I'm just wondering is it okay that I just do it with memcpy(), by digging into the code for the definition of struct sqlite3 and count the total bytes of this struct? Any ideas or suggestions are appreciated! ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users