While looking at how best to get back data from an insert, I see that in
pgsql the recommended way is via INSERT ... RETURNING.  Such as:

        /* Copy the message table entry of the message. */
        snprintf(query, DEF_QUERYSIZE,
                 "INSERT INTO %smessages (mailbox_idnr,"
                 "physmessage_id, seen_flag, answered_flag, deleted_flag, "
                 "flagged_flag, recent_flag, draft_flag, unique_id, status) "
                 "SELECT %llu, "
                 "physmessage_id, seen_flag, answered_flag, deleted_flag, "
                 "flagged_flag, recent_flag, draft_flag, '%s', status "
-                "FROM %smessages WHERE mailbox_idnr = %llu AND message_idnr = 
%llu",
+                "FROM %smessages WHERE mailbox_idnr = %llu AND message_idnr = 
%llu "
+                "RETURNING message_idnr",
                 DBPFX, mailbox_to, unique_id, DBPFX, mailbox_from, msg_idnr);

After which a db_get_result(0, 0) can be used instead of the current
db_insert_result("message_idnr").

So, I think db_insert_result() should be rewritten for pgsql to use
db_get_result() and something should be added to enable adding the
"RETURNING foo" string to the query when applicable.

Unfortunately, according to their docs, neither sqlite nor mysql (even
version 6) supports INSERT RETURNING.  So this will require a new
function in the dbfoosql modules which should take a char* (just like
db_insert_result()) and return a char* to either and empty string for
mysql and sqlite or "RETURNING %s" for pgsql.

Looking at how, eg, db_add_sievescript() works, I take it this new
function should work something like dm_stresc() does and that the
calling function would then be responsible to g_free() the returned
char*, yes?  Ie, use g_new0() to allocate the new string?

Is there any special trick when allocating ""?  Or should I use " "?

Or, for that matter, is there any preference between using sprintf(3) vs
some other method to append the argument char* to the char* "RETURNING "?

I beleive this will be a benefit even w/o the contig uids work.

All thoughts on how best to implement this change are most welcome!

-JimC
-- 
James Cloos <[EMAIL PROTECTED]>         OpenPGP: 1024D/ED7DAEA6
_______________________________________________
Dbmail-dev mailing list
Dbmail-dev@dbmail.org
http://twister.fastxs.net/mailman/listinfo/dbmail-dev

Reply via email to