Ejemplo n.º 1
0
        public int ExecuteNonQuery()
        {
            _conn.TraceListener.WriteLine("Executing: {0}", this);
            if (_conn.ReadOnlyCaching)
            {
                var commandString = this.ToString().ToLower();
                ReadOnlyQueryCache.CheckIfCacheNeedsClearing(_conn, commandString);
            }

            var stmt = Prepare();
            var r    = _sqlitePlatform.SQLiteApi.Step(stmt);

            Finalize(stmt);
            if (r == Result.Done)
            {
                var rowsAffected = _sqlitePlatform.SQLiteApi.Changes(_conn.Handle);
                return(rowsAffected);
            }
            if (r == Result.Error)
            {
                var msg = _sqlitePlatform.SQLiteApi.Errmsg16(_conn.Handle);
                throw SQLiteException.New(r, msg);
            }
            if (r == Result.Constraint)
            {
                if (_sqlitePlatform.SQLiteApi.ExtendedErrCode(_conn.Handle) == ExtendedResult.ConstraintNotNull)
                {
                    throw NotNullConstraintViolationException.New(r, _sqlitePlatform.SQLiteApi.Errmsg16(_conn.Handle));
                }
            }
            throw SQLiteException.New(r, r.ToString());
        }
        public int ExecuteNonQuery(object[] source)
        {
            Connection.TraceListener.WriteLine("Executing: {0}", CommandText);
            if (Connection.ReadOnlyCaching)
            {
                var commandString = CommandText.ToLower();
                ReadOnlyQueryCache.CheckIfCacheNeedsClearing(Connection, commandString);
            }

            if (!Initialized)
            {
                Statement   = Prepare();
                Initialized = true;
            }

            var sqlitePlatform = Connection.Platform;

            //bind the values.
            if (source != null)
            {
                for (var i = 0; i < source.Length; i++)
                {
                    SQLiteCommand.BindParameter(sqlitePlatform.SQLiteApi, Statement, i + 1, source[i],
                                                Connection.StoreDateTimeAsTicks, Connection.Serializer);
                }
            }
            var r = sqlitePlatform.SQLiteApi.Step(Statement);

            if (r == Result.Done)
            {
                var rowsAffected = sqlitePlatform.SQLiteApi.Changes(Connection.Handle);
                sqlitePlatform.SQLiteApi.Reset(Statement);
                return(rowsAffected);
            }
            if (r == Result.Error)
            {
                var msg = sqlitePlatform.SQLiteApi.Errmsg16(Connection.Handle);
                sqlitePlatform.SQLiteApi.Reset(Statement);
                throw SQLiteException.New(r, msg);
            }
            if (r == Result.Constraint && sqlitePlatform.SQLiteApi.ExtendedErrCode(Connection.Handle) == ExtendedResult.ConstraintNotNull)
            {
                sqlitePlatform.SQLiteApi.Reset(Statement);
                throw NotNullConstraintViolationException.New(r, sqlitePlatform.SQLiteApi.Errmsg16(Connection.Handle));
            }
            sqlitePlatform.SQLiteApi.Reset(Statement);
            throw SQLiteException.New(r, r.ToString());
        }