Exemplo n.º 1
0
        private DBInsertCommand CreateInsertCommand(DBConnection conn, string extra)
        {
            Column[] cols = this.InsertColumns;
            string   insertSql;

            if (!cols.Any() && this.Columns.Count() == 1 && this.Columns[0].IsAutoInc)
            {
                insertSql = string.Format("INSERT {1} INTO \"{0}\" DEFAULT VALUES", this.TableName, extra);
            }
            else
            {
                bool replacing = string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0;

                if (replacing)
                {
                    cols = this.InsertOrReplaceColumns;
                }

                insertSql = string.Format("INSERT {3} INTO \"{0}\"({1}) VALUES ({2})", this.TableName,
                                          string.Join(",", (from c in cols select "\"" + c.Name + "\"").ToArray()),
                                          string.Join(",", (from c in cols select "?").ToArray()), extra);
            }
            var cmd = new DBInsertCommand(conn);

            cmd.CommandText = insertSql;
            return(cmd);
        }
Exemplo n.º 2
0
        public DBInsertCommand GetInsertCommand(DBConnection conn, string extra)
        {
            if (_insertCommand == null)
            {
                _insertCommand      = CreateInsertCommand(conn, extra);
                _insertCommandExtra = extra;
            }
            else if (_insertCommandExtra != extra)
            {
                _insertCommand.Dispose();
                _insertCommand      = CreateInsertCommand(conn, extra);
                _insertCommandExtra = extra;
            }

            return(_insertCommand);
        }