Beispiel #1
0
 protected internal void Dispose()
 {
     if (_insertCommand != null)
     {
         _insertCommand.Dispose();
         _insertCommand = null;
     }
 }
Beispiel #2
0
 public PreparedSqlLiteInsertCommand GetInsertCommand(SQLiteConnection 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);
 }
Beispiel #3
0
        public int Insert(object obj, string extra, Type objType)
        {
            if (obj == null || objType == null)
            {
                return(0);
            }
            TableMapping mapping = GetMapping(objType);

            if (mapping.PK != null && mapping.PK.IsAutoGuid)
            {
                PropertyInfo property = objType.GetProperty(mapping.PK.PropertyName);
                if (property != null && property.GetGetMethod().Invoke(obj, null).Equals(Guid.Empty))
                {
                    property.SetValue(obj, Guid.NewGuid(), null);
                }
            }
            TableMapping.Column[] array = (string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) != 0) ? mapping.InsertColumns : mapping.InsertOrReplaceColumns;
            object[] array2             = new object[array.Length];
            for (int i = 0; i < array2.Length; i++)
            {
                array2[i] = array[i].GetValue(obj);
            }
            PreparedSqlLiteInsertCommand insertCommand = mapping.GetInsertCommand(this, extra);
            int result;

            try
            {
                result = insertCommand.ExecuteNonQuery(array2);
            }
            catch (SQLiteException ex)
            {
                if (SQLite3.ExtendedErrCode(Handle) == SQLite3.ExtendedResult.ConstraintNotNull)
                {
                    throw NotNullConstraintViolationException.New(ex.Result, ex.Message, mapping, obj);
                }
                throw;
                IL_0120 :;
            }
            if (mapping.HasAutoIncPK)
            {
                long id = SQLite3.LastInsertRowid(Handle);
                mapping.SetAutoIncPK(obj, id);
            }
            return(result);
        }
Beispiel #4
0
        private PreparedSqlLiteInsertCommand CreateInsertCommand(SQLiteConnection conn, string extra)
        {
            Column[] source = InsertColumns;
            string   commandText;

            if (!source.Any() && Columns.Count() == 1 && Columns[0].IsAutoInc)
            {
                commandText = string.Format("insert {1} into \"{0}\" default values", TableName, extra);
            }
            else
            {
                if (string.Compare(extra, "OR REPLACE", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    source = InsertOrReplaceColumns;
                }
                commandText = string.Format("insert {3} into \"{0}\"({1}) values ({2})", TableName, string.Join(",", (from c in source
                                                                                                                      select "\"" + c.Name + "\"").ToArray()), string.Join(",", (from c in source
                                                                                                                                                                                 select "?").ToArray()), extra);
            }
            PreparedSqlLiteInsertCommand preparedSqlLiteInsertCommand = new PreparedSqlLiteInsertCommand(conn);

            preparedSqlLiteInsertCommand.CommandText = commandText;
            return(preparedSqlLiteInsertCommand);
        }