private void BindData(Sqlite3Statement statement, params object[] parameters)
        {
            if (parameters != null)
            {
                for (int i = 1; i <= parameters.Length; i++)
                {
                    object o = parameters[i - 1];
                    if (o == null)
                    {
                        Sqlite3.sqlite3_bind_null(statement, i);
                        continue;
                    }

                    var type = o.GetType();
                    var dt   = o as DateTime?;
                    if (dt.HasValue)
                    {
                        string ticks = dt.Value.Ticks.ToString();
                        Sqlite3.sqlite3_bind_text(statement, i, ticks);
                    }
                    else if (type == typeof(string))
                    {
                        Sqlite3.sqlite3_bind_text(statement, i, (string)o);
                    }
                    else if ((typeof(Int32) == type) ||
                             (typeof(Boolean) == type) ||
                             (typeof(Byte) == type) ||
                             (typeof(UInt16) == type) ||
                             (typeof(Int16) == type) ||
                             (typeof(sbyte) == type) ||
                             (typeof(Int64) == type) ||
                             (typeof(long) == type) ||
                             (typeof(UInt32) == type))
                    {
                        Sqlite3.sqlite3_bind_int64(statement, i, (Int64)Convert.ChangeType(o, typeof(Int64)));
                    }
                    else if ((typeof(double) == type) ||
                             (typeof(float) == type) ||
                             (typeof(decimal) == type))
                    {
                        Sqlite3.sqlite3_bind_double(statement, i, (double)o);
                    }
                    else if (type == typeof(byte[]))
                    {
                        Sqlite3.sqlite3_bind_blob(statement, i, (byte[])o);
                    }
                }
            }
        }
예제 #2
0
 public static int BindInt64(Sqlite3Statement stmt, int index, long val)
 {
     return(Sqlite3.sqlite3_bind_int64(stmt, index, val));
 }