Пример #1
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 ((_cnn != null) && (_cnn._sql != null))
                {
                    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 != null) && _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;
            }
        }
Пример #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////

        private void DisposeStatements()
        {
            if (_statementList == null)
            {
                return;
            }

            int x = _statementList.Count;

            for (int n = 0; n < x; n++)
            {
                SQLiteStatement stmt = _statementList[n];
                if (stmt == null)
                {
                    continue;
                }
                stmt.Dispose();
            }

            _statementList = null;
        }
Пример #3
0
        internal SQLiteStatement BuildNextCommand()
        {
            SQLiteStatement item = null;
            SQLiteStatement statement2;

            try
            {
                if (this._statementList == null)
                {
                    this._remainingText = this._commandText;
                }
                item = this._cnn._sql.Prepare(this._cnn, this._remainingText, (this._statementList == null) ? null : this._statementList[this._statementList.Count - 1], (uint)(this._commandTimeout * 0x3e8), out this._remainingText);
                if (item != null)
                {
                    item._command = this;
                    if (this._statementList == null)
                    {
                        this._statementList = new List <SQLiteStatement>();
                    }
                    this._statementList.Add(item);
                    this._parameterCollection.MapParameters(item);
                    item.BindParameters();
                }
                statement2 = item;
            }
            catch (Exception)
            {
                if (item != null)
                {
                    if (this._statementList.Contains(item))
                    {
                        this._statementList.Remove(item);
                    }
                    item.Dispose();
                }
                this._remainingText = null;
                throw;
            }
            return(statement2);
        }
Пример #4
0
        /// <summary>
        /// Verifies that all SQL queries associated with the current command text
        /// can be successfully compiled.  A <see cref="SQLiteException" /> will be
        /// raised if any errors occur.
        /// </summary>
        public void VerifyOnly()
        {
            CheckDisposed();

            SQLiteConnection connection = _cnn;

            SQLiteConnection.Check(connection); /* throw */
            SQLiteBase sqlBase = connection._sql;

            if ((connection == null) || (sqlBase == null))
            {
                throw new SQLiteException("invalid or unusable connection");
            }

            List <SQLiteStatement> statements       = null;
            SQLiteStatement        currentStatement = null;

            try
            {
                string          text              = _commandText;
                uint            timeout           = (uint)(_commandTimeout * 1000);
                SQLiteStatement previousStatement = null;

                while ((text != null) && (text.Length > 0))
                {
                    currentStatement = sqlBase.Prepare(
                        connection, text, previousStatement, timeout,
                        ref text); /* throw */

                    previousStatement = currentStatement;

                    if (currentStatement != null)
                    {
                        if (statements == null)
                        {
                            statements = new List <SQLiteStatement>();
                        }

                        statements.Add(currentStatement);
                        currentStatement = null;
                    }

                    if (text == null)
                    {
                        continue;
                    }
                    text = text.Trim();
                }
            }
            finally
            {
                if (currentStatement != null)
                {
                    currentStatement.Dispose();
                    currentStatement = null;
                }

                if (statements != null)
                {
                    foreach (SQLiteStatement statement in statements)
                    {
                        if (statement == null)
                        {
                            continue;
                        }

                        statement.Dispose();
                    }

                    statements.Clear();
                    statements = null;
                }
            }
        }