public object ExecInsert(IDatabaseAccess db, string tableName, string autoIncrementName, IDictionary <string, object> data) { db.Exec( CommonDatabaseDetails.FormatInsertCommand(this, tableName, data.Keys), data.Values.ToArray() ); if (String.IsNullOrEmpty(autoIncrementName)) { return(null); } // per-connection, robust to triggers // http://www.sqlite.org/c3ref/last_insert_rowid.html return(db.Cell <long>(false, "select last_insert_rowid()")); }
public object ExecInsert(IDatabaseAccess db, string tableName, string autoIncrementName, IDictionary <string, object> data) { db.Exec( CommonDatabaseDetails.FormatInsertCommand(this, tableName, data.Keys, defaultsExpr: "values ()"), data.Values.ToArray() ); if (String.IsNullOrEmpty(autoIncrementName)) { return(null); } // per-connection, http://stackoverflow.com/q/21185666 // robust to triggers, http://dba.stackexchange.com/a/25141 return(db.Cell <object>(false, "select last_insert_id()")); }
public object ExecInsert(IDatabaseAccess db, string tableName, string autoIncrementName, IDictionary <string, object> data) { var hasAutoIncrement = !String.IsNullOrEmpty(autoIncrementName); var postfix = hasAutoIncrement ? "returning " + QuoteName(autoIncrementName) : null; var sql = CommonDatabaseDetails.FormatInsertCommand(this, tableName, data.Keys, postfix: postfix); var values = data.Values.ToArray(); if (hasAutoIncrement) { return(db.Cell <object>(false, sql, values)); } db.Exec(sql, values); return(null); }