Example #1
0
        private void ExecuteFirstStep()
        {
            _Done      = true;
            _FirstRead = true;

            // Exec first step and get column info.
            _Statement = _Command.Statements[_StatementIndex];
            _Statement.Compile();
            _NativeMethods.busy_timeout(_Command.CommandTimeout);

            SQLiteCode res = _Statement.Step();

            if (res == SQLiteCode.RowReady || res == SQLiteCode.Done)
            {
                _FieldNames             = new String[_Statement.GetColumnCount()];
                _FieldTypes             = new Type[_Statement.GetColumnCount()];
                _ColumnNameStartIndexes = new int[_Statement.GetColumnCount()];

                // Get column info.
                for (int i = 0; i < _Statement.GetColumnCount(); i++)
                {
                    _FieldNames[i]             = _Statement.GetColumnName(i);
                    _FieldTypes[i]             = SQLType2Type(_Statement.GetColumnType(i));
                    _ColumnNameStartIndexes[i] = _FieldNames[i].IndexOf('.') + 1;
                }

                _Done = res == SQLiteCode.Done;
            }
            else if (res == SQLiteCode.Error)
            {
                _Statement.Dispose();
            }
            else
            {
                throw new SQLiteException(string.Format("Unknown SQLite error code {0}.", res));
            }
        }
Example #2
0
        /// <summary>
        /// parse the command text and split it into separate SQL commands
        /// </summary>
        private void ParseCommand(string cmd)
        {
            _Statements.Clear();

            if (cmd.Length == 0)
            {
                return;
            }

            char[] Terminators =
            { StatementTerminator,
              NamedParameterBeginChar,
              Quote,
              DoubleQuote,
//					UnnamedParameterBeginChar,
              CreateTriggerBeginChar1,
              CreateTriggerBeginChar2 };

            int           index      = 0;
            ArrayList     paramNames = new ArrayList();
            StringBuilder sb         = new StringBuilder(cmd.Length);

            while (index < cmd.Length)
            {
                int foundIndex = cmd.IndexOfAny(Terminators, index);

                AppendUpToFoundIndex(sb, cmd, foundIndex, ref index);

                if (foundIndex < 0)
                {
                    break;
                }

                switch (cmd[foundIndex])
                {
                case Quote:
                case DoubleQuote:
                    AppendUpToSameChar(sb, cmd, foundIndex, out index);
                    break;

                case NamedParameterBeginChar:
                    AppendNamedParameter(sb, cmd, foundIndex, paramNames, out index);
                    break;

                //case UnnamedParameterBeginChar:
                //    paramNames.Add(null);
                //    sb.Append(UnnamedParameterBeginChar);
                //    index = foundIndex+1;
                //    break;

                case StatementTerminator:
                    TerminateStatement(sb, ref paramNames);
                    index = foundIndex + 1;
                    break;

                case CreateTriggerBeginChar1:
                case CreateTriggerBeginChar2:
                    AppendTrigger(sb, cmd, foundIndex, out index);
                    break;

                default:
                    throw new SQLiteException(string.Format("Found the unexpected terminator '{0}' at the position {1}.", cmd[foundIndex], foundIndex));
                }
            }
            TerminateStatement(sb, ref paramNames);

            // now iterate all SQL statements and assign
            // the starting index of unnamed parameters inside Parameters collection
            int unnamedParameterCount = 0;

            for (int i = 0; i < _Statements.Count; ++i)
            {
                SQLiteStatement statement = _Statements[i];

                statement.SetUnnamedParametersStartIndex(unnamedParameterCount);

                unnamedParameterCount += statement.GetUnnamedParameterCount();
            }
        }
Example #3
0
 public void Add(SQLiteStatement statement)
 {
     List.Add(statement);
 }
Example #4
0
        private void ExecuteFirstStep()
        {
            _Done = true;
            _FirstRead = true;

            // Exec first step and get column info.
            _Statement = _Command.Statements[_StatementIndex];
            _Statement.Compile();
            _NativeMethods.busy_timeout(_Command.CommandTimeout);

            SQLiteCode res = _Statement.Step();
            if (res == SQLiteCode.RowReady || res == SQLiteCode.Done)
            {
                _FieldNames = new String[_Statement.GetColumnCount()];
                _FieldTypes = new Type[_Statement.GetColumnCount()];
                _ColumnNameStartIndexes = new int[_Statement.GetColumnCount()];

                // Get column info.
                for (int i = 0; i < _Statement.GetColumnCount(); i++)
                {
                    _FieldNames[i] = _Statement.GetColumnName(i);
                    _FieldTypes[i] = SQLType2Type(_Statement.GetColumnType(i));
                    _ColumnNameStartIndexes[i] = _FieldNames[i].IndexOf('.') + 1;
                }

                _Done = res == SQLiteCode.Done;
            }
            else if (res == SQLiteCode.Error) _Statement.Dispose();
            else throw new SQLiteException(string.Format("Unknown SQLite error code {0}.", res));
        }
 public void Add(SQLiteStatement statement)
 {
     List.Add(statement);
 }