Thanks alot Julian,
Your solution works fine but it can not return the exception cause in case the
update request failed. For example, when someone try to update a primary key
field, how can we catch this exception (table, field name, mySQL error message
...). I hoped the soci_mysql_exception could do this but it did not :(
RegardsVDung
--- On Sat, 3/5/11, Julian Taylor <[email protected]> wrote:
From: Julian Taylor <[email protected]>
Subject: Re: [SOCI-users] Remote database and exception handling
To: [email protected]
Date: Saturday, March 5, 2011, 4:33 AM
On 01/03/11 14:27, Doan Viet Dung wrote:
> Thanks you very much for your reply, Julian, quite useful
>
> However, in case of update, it seems that indicator does not work as
> well. I can not handle an exception thrown from such update query.
>
> sql << "UPDATE my_table SET "
> << "name =: first_name '"
> << " WHERE UsrId = :user_id ", use(first_name,ind), use(user_id);
> For example when user_id does not exist, of course the row is not
> updated but I got no message using
> switch (ind)
> {
> case i_ok:
> message here
> break;
> case i_null:
> message here
> break;
> case i_truncated:
> message here
> break;
> }
> Any idea how to catch such exception from an update query ???
>
> Regards
> VDung
>
>
you could check the number of affected rows:
statement st = (sql.prepare <<
"UPDATE t1 SET x=5 WHERE b = 5");
st1.execute(false);
cout << "affected " << st.get_affected_rows() << endl;
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
-----Inline Attachment Follows-----
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users
------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users