Ejemplo 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.IsNullOrWhiteSpace(_remainingText) == false)
                {
                    return(BuildNextCommand());
                }
                else
                {
                    return(null); // No more commands
                }
            }

            SqliteStatement stmt = _statementList[index];

            stmt.BindParameters();

            return(stmt);
        }
Ejemplo 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);
                stmt = _cnn._sql.Prepare(_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;
            }
        }