Esempio n. 1
0
        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()
                );

            return(string.IsNullOrEmpty(autoIncrementName)
                ? null
                : db.Cell <object>(false, "SELECT LAST_INSERT_ID()"));

            // per-connection, http://stackoverflow.com/q/21185666
            // robust to triggers, http://dba.stackexchange.com/a/25141
        }
Esempio n. 2
0
        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()"));
        }
Esempio n. 3
0
        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);
        }