BindParameters() private method

Bind all parameters, making sure the caller didn't miss any
private BindParameters ( ) : void
return void
Esempio n. 1
0
        internal SqliteStatement GetStatement(int index)
        {
            // Haven't built any statements yet
            if (_statementList == null)
            {
                return(BuildNextCommand());
            }

            // If we're at the last built statement and want the next unbuilt statement, then build it
            if (index == _statementList.Count)
            {
                if (String.IsNullOrEmpty(_remainingText) == false)
                {
                    return(BuildNextCommand());
                }
                else
                {
                    return(null); // No more commands
                }
            }

            SqliteStatement stmt = _statementList[index];

            stmt.BindParameters();

            return(stmt);
        }
Esempio n. 2
0
        /// <summary>
        /// Builds an array of prepared statements for each complete SQL statement in the command text
        /// </summary>
        internal SqliteStatement BuildNextCommand()
        {
            SqliteStatement stmt = null;

            try
            {
                if (_statementList == null)
                {
                    _remainingText = _commandText;
                }

                stmt = _cnn._sql.Prepare(_cnn, _remainingText, (_statementList == null) ? null : _statementList[_statementList.Count - 1], (uint)(_commandTimeout * 1000), out _remainingText);
                if (stmt != null)
                {
                    stmt._command = this;
                    if (_statementList == null)
                    {
                        _statementList = new List <SqliteStatement>();
                    }

                    _statementList.Add(stmt);

                    _parameterCollection.MapParameters(stmt);
                    stmt.BindParameters();
                }
                return(stmt);
            }
            catch (Exception)
            {
                if (stmt != null)
                {
                    if (_statementList.Contains(stmt))
                    {
                        _statementList.Remove(stmt);
                    }

                    stmt.Dispose();
                }

                // If we threw an error compiling the statement, we cannot continue on so set the remaining text to null.
                _remainingText = null;

                throw;
            }
        }
Esempio n. 3
0
        internal override int Reset(SqliteStatement stmt)
        {
            int n;

#if !SQLITE_STANDARD
            n = UnsafeNativeMethods.sqlite3_reset_interop(stmt._sqlite_stmt);
#else
            n = UnsafeNativeMethods.sqlite3_reset(stmt._sqlite_stmt);
#endif

            // If the schema changed, try and re-prepare it
            if (n == 17) // SQLITE_SCHEMA
            {
                // Recreate a dummy statement
                string str;
                using (SqliteStatement tmp = Prepare(null, stmt._sqlStatement, null, (uint)(stmt._command._commandTimeout * 1000), out str))
                {
                    // Finalize the existing statement
                    stmt._sqlite_stmt.Dispose();
                    // Reassign a new statement pointer to the old statement and clear the temporary one
                    stmt._sqlite_stmt = tmp._sqlite_stmt;
                    tmp._sqlite_stmt  = null;

                    // Reapply parameters
                    stmt.BindParameters();
                }
                return(-1);            // Reset was OK, with schema change
            }
            else if (n == 6 || n == 5) // SQLITE_LOCKED || SQLITE_BUSY
            {
                return(n);
            }

            if (n > 0)
            {
                throw new SqliteException(n, SQLiteLastError());
            }

            return(0); // We reset OK, no schema changes
        }
Esempio n. 4
0
        internal override int Reset(SqliteStatement stmt)
        {
            int n;

            n = UnsafeNativeMethods.sqlite3_reset(stmt._sqlite_stmt);

            // If the schema changed, try and re-prepare it
            if (n == 17) // SQLITE_SCHEMA
            {
                // Recreate a dummy statement
                string str;
                using (SqliteStatement tmp = Prepare(stmt._sqlStatement, null, out str))
                {
                    // Finalize the existing statement
                    FinalizeStatement(stmt);

                    // Reassign a new statement pointer to the old statement and clear the temporary one
                    stmt._sqlite_stmt = tmp._sqlite_stmt;
                    tmp._sqlite_stmt  = IntPtr.Zero;

                    // Reapply parameters
                    stmt.BindParameters();
                }
                return(-1);  // Reset was OK, with schema change
            }
            else if (n == 6) // SQLITE_LOCKED
            {
                return(n);
            }

            if (n > 0)
            {
                throw new SqliteException(n, SqliteLastError());
            }

            return(0); // We reset OK, no schema changes
        }
Esempio n. 5
0
        internal override int Reset(SqliteStatement stmt)
        {
            int n = UnsafeNativeMethods.sqlite3_reset(stmt._sqlite_stmt);

            // If the schema changed, try and re-prepare it
            if (n == 17) // SQLITE_SCHEMA
            {
                // Recreate a dummy statement
                var timeout = (uint)(stmt._command._commandTimeout * 1000);
                string str;
                using (SqliteStatement tmp = Prepare(null, stmt._sqlStatement, null, timeout, out str))
                {
                    // Finalize the existing statement
                    stmt._sqlite_stmt.Dispose();
                    // Reassign a new statement pointer to the old statement and clear the temporary one
                    stmt._sqlite_stmt = tmp._sqlite_stmt;
                    tmp._sqlite_stmt = null;

                    // Reapply parameters
                    stmt.BindParameters();
                }

                return -1; // Reset was OK, with schema change
            }

            if (n == 6 || n == 5) // SQLITE_LOCKED || SQLITE_BUSY
            {
                return n;
            }

            if (n > 0)
            {
                throw new SqliteException(n, SQLiteLastError());
            }

            return 0; // We reset OK, no schema changes
        }