dbTalk Databases Forums  

query.execute not working

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss query.execute not working in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Chuck Haines
 
Posts: n/a

Default query.execute not working - 01-24-2006 , 02:05 PM






------=_Part_11137_10435584.1138133100978
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hello all,
I'm trying to run the following code:

query =3D conn.query();
ttime =3D time( NULL );
sprintf( dTime, "%d000", ttime );
sql =3D "insert into Survey values ('";
sql +=3D dTime;
sql +=3D "', '";
sql +=3D dTime;
sql +=3D "', 'Information', 'Information')";
query << sql;
query.execute();
cout << "Error: " << query.error() << endl;

However, when I try and go look at the database, the information has not
been inserted into the Survey table. I have already called
conn.connectwith the correct parameters and no exceptions are being
thrown from that.
Any help would be appreciated.

Thanks,
Chuck

--
Chuck Haines
chaines (AT) gmail (DOT) com
http://www.maxslack.com
-------------------------------------------
Tau Kappa Epsilon Fraternity
Fraternity For Life Alumni
-------------------------------------------
AIM: CyberGrex
YIM: CyberGrex_27
ICQ: 3707881
-------------------------------------------
GPG Fingerprint: 303A AB50 4EA9 70ED 2E30 2368 C9CD CCB5 4BD7 0989
GPG Key: http://www.maxslack.com/gpgkey.txt

------=_Part_11137_10435584.1138133100978--

Reply With Quote
  #2  
Old   
Warren Young
 
Posts: n/a

Default Re: query.execute not working - 01-24-2006 , 11:50 PM






Chuck Haines wrote:
Quote:
query = conn.query();
ttime = time( NULL );
sprintf( dTime, "%d000", ttime );
sql = "insert into Survey values ('";
sql += dTime;
sql += "', '";
sql += dTime;
sql += "', 'Information', 'Information')";
query << sql;
*Dude*.... Please read a book that covers C++ idioms. This looks like
it's trying to be Perl or BASIC. I'm not trying to pick on you. It's
just that if you write C++ as though it were some other language, it
will not work very well. Rewriting it into proper C++:

query = conn.query();
snprintf( dTime, sizeof(dTime), "%d000", time(0) );
query << "insert into Survey values (" << mysqlpp::quote <<
dTime << ", " << mysqlpp::quote << dTime <<
", 'Information', 'Information')";
query.execute();

Notice that I changed your sprintf() to snprintf(). sprintf() should
not be used any more; it is a prime candidate for buffer overflow
errors. snprintf() is new in C99, and most compilers offer something
like it, if not exactly like it. (Microsoft prefers _snprintf(), for
instance.) My rewrite assumes that dTime is an array, and not a pointer
to dynamically-allocated memory.

Also, I think you could profit from looking into MySQL++'s SSQLS
feature. It reduces the drudgery in the code above.

Quote:
cout << "Error: " << query.error() << endl;
Unless I'm missing something, this won't ever give you anything useful.
Any true errors will be signaled with exceptions, totally bypassing
this code.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #3  
Old   
Chuck Haines
 
Posts: n/a

Default Re: query.execute not working - 01-25-2006 , 05:33 AM



------=_Part_19528_19779648.1138188762757
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I had a brain cramp yesterday. I have since figured everything out. I
haven't had to program in C++ for about 6 years and have been thrown into
this project. Also, I can't use SSQL because I'm compiling on QNX and it
doesn't work. So I've got to do it the old fashion way. Also, I've figure
out my other email as well.

On 1/25/06, Warren Young <mysqlpp (AT) etr-usa (DOT) com> wrote:
Quote:
Chuck Haines wrote:

query =3D conn.query();
ttime =3D time( NULL );
sprintf( dTime, "%d000", ttime );
sql =3D "insert into Survey values ('";
sql +=3D dTime;
sql +=3D "', '";
sql +=3D dTime;
sql +=3D "', 'Information', 'Information')";
query << sql;

*Dude*.... Please read a book that covers C++ idioms. This looks like
it's trying to be Perl or BASIC. I'm not trying to pick on you. It's
just that if you write C++ as though it were some other language, it
will not work very well. Rewriting it into proper C++:

query =3D conn.query();
snprintf( dTime, sizeof(dTime), "%d000", time(0) );
query << "insert into Survey values (" << mysqlpp::quote
dTime << ", " << mysqlpp::quote << dTime
", 'Information', 'Information')";
query.execute();

Notice that I changed your sprintf() to snprintf(). sprintf() should
not be used any more; it is a prime candidate for buffer overflow
errors. snprintf() is new in C99, and most compilers offer something
like it, if not exactly like it. (Microsoft prefers _snprintf(), for
instance.) My rewrite assumes that dTime is an array, and not a pointer
to dynamically-allocated memory.

Also, I think you could profit from looking into MySQL++'s SSQLS
feature. It reduces the drudgery in the code above.

cout << "Error: " << query.error() << endl;

Unless I'm missing something, this won't ever give you anything useful.
Any true errors will be signaled with exceptions, totally bypassing
this code.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu... gmail (DOT) =
com



--
Chuck Haines
chaines (AT) gmail (DOT) com
http://www.maxslack.com
-------------------------------------------
Tau Kappa Epsilon Fraternity
Fraternity For Life Alumni
-------------------------------------------
AIM: CyberGrex
YIM: CyberGrex_27
ICQ: 3707881
-------------------------------------------
GPG Fingerprint: 303A AB50 4EA9 70ED 2E30 2368 C9CD CCB5 4BD7 0989
GPG Key: http://www.maxslack.com/gpgkey.txt

------=_Part_19528_19779648.1138188762757--


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.