Пример #1
0
 private void BindConditions(IntPtr stmt)
 {
     foreach (var cond in conditions)
     {
         int paramIndex = SQLite3.BindParameterIndex(stmt, cond.Key);
         var bindresult = SQLite3.GetBindFunc(SQLite3.GetSQLType(cond.Value.GetType()))(stmt, paramIndex, cond.Value);
         SQLite3.CheckResult(db, bindresult);
     }
 }
Пример #2
0
        private void BindAll(Sqlite3Statement stmt)
        {
            int nextIdx = 1;

            foreach (Binding b in _bindings)
            {
                if (b.Name != null)
                {
                    b.Index = SQLite3.BindParameterIndex(stmt, b.Name);
                }
                else
                {
                    b.Index = nextIdx++;
                }

                BindParameter(stmt, b.Index, b.Value, _conn.StoreDateTimeAsTicks);
            }
        }
Пример #3
0
        public void Insert <T>(string table, T values)
        {
            var fis       = typeof(T).GetFields();
            var fieldList = ArrayUtils.ConvertAll(fis, x => x.Name);
            var valueList = ArrayUtils.ConvertAll(fis, x => "@" + x.Name);

            string SQL  = "INSERT INTO " + table + " (" + string.Join(", ", fieldList) + ") VALUES ( " + string.Join(", ", valueList) + " )";
            IntPtr stmt = SQLite3.Prepare2(db, SQL);

            foreach (var fi in fis)
            {
                int paramIndex = SQLite3.BindParameterIndex(stmt, "@" + fi.Name);
                var bindresult = SQLite3.GetBindFunc(SQLite3.GetSQLType(fi.FieldType))(stmt, paramIndex, fi.GetValue(values));
                SQLite3.CheckResult(db, bindresult);
            }
            var stepresult = SQLite3.Step(stmt);

            SQLite3.CheckResult(db, stepresult);
            SQLite3.Finalize(stmt);
        }
Пример #4
0
        void BindAll(Sqlite3Statement stmt)
        {
            int nextIdx = 1;

            foreach (var b in _bindings)
            {
                if (b.Name != null)
                {
                    b.Index = SQLite3.BindParameterIndex(stmt, b.Name);
                }
                else
                {
                    b.Index = nextIdx++;
                }

                var SQLiteType = SQLite3.GetSQLiteType(b.Value.GetType());
                if (SQLiteType != null)
                {
                    SQLiteType.Bind(stmt, b.Index, b.Value, _conn.StoreDateTimeAsTicks);
                }
            }
        }
Пример #5
0
 public int ColumnIndex(String columnName)
 {
     return(SQLite3.BindParameterIndex(statement, columnName));
 }
Пример #6
0
        void BindAll(IntPtr stmt)
        {
            int nextIdx = 1;

            foreach (var b in _bindings)
            {
                if ((b.Name != null) && (CommandText.IndexOf(b.Name) != -1))
                {
                    b.Index = SQLite3.BindParameterIndex(stmt, b.Name);
                }
                else
                {
                    b.Index = nextIdx++;
                }
            }
            for (int c = 0; c < _bindings.Count; c++)
            {
                var b = _bindings[c];
                if (b.Value == null)
                {
                    int n = SQLite3.BindNull(stmt, b.Index);
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
                if (b.Value is Byte || b.Value is UInt16 || b.Value is SByte || b.Value is Int16 || b.Value is Int32 || b.Value is Boolean)
                {
                    int n = SQLite3.BindInt(stmt, b.Index, Convert.ToInt32(b.Value, CultureInfo.InvariantCulture));
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
                if (b.Value is UInt32 || b.Value is Int64)
                {
                    int n = SQLite3.BindInt64(stmt, b.Index, Convert.ToInt64(b.Value, CultureInfo.InvariantCulture));
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
                if (b.Value is Single || b.Value is Double || b.Value is Decimal)
                {
                    int n = SQLite3.BindDouble(stmt, b.Index, Convert.ToDouble(b.Value, CultureInfo.InvariantCulture));
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
                if (b.Value is String)
                {
                    int n = SQLite3.BindText(stmt, b.Index, b.Value.ToString(), -1, IntPtr.Zero);
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
                if (b.Value is byte[])
                {
                    int n = SQLite3.BindBlob(stmt, b.Index, (byte[])b.Value, ((byte[])b.Value).Length, IntPtr.Zero);
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
                if (b.Value is DateTime)
                {
                    int n = SQLite3.BindText(stmt, b.Index, DateToString((DateTime)b.Value), -1, IntPtr.Zero);
                    if (n > 0)
                    {
                        throw new SQLiteException((SQLite3.Result)n, SQLiteLastError());
                    }
                    continue;
                }
            }
        }