コード例 #1
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;
                }
            }
        }