ToDbFormat() public static method

public static ToDbFormat ( Type type, object value ) : object
type System.Type
value object
return object
Ejemplo n.º 1
0
        public object GetValue(object target)
        {
            object result = field_info != null
                ? field_info.GetValue(target)
                : property_info.GetValue(target, null);

            return(SqliteUtils.ToDbFormat(type, result));
        }
Ejemplo n.º 2
0
        public void SetProperty <U> (T item, U value, DbColumn column)
        {
            CheckProperty(typeof(U), column);

            Connection.Execute(string.Format(
                                   "UPDATE {0} SET {1}='{2}' WHERE {3}={4}",
                                   TableName, column.Name,
                                   SqliteUtils.ToDbFormat(typeof(U), value),
                                   key.Name, key.GetValue(item)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Takes the return value from Invoke() and Final() and figures out how to return it to Sqlite's context.
 /// </summary>
 /// <param name="context">The context the return value applies to</param>
 /// <param name="returnValue">The parameter to return to Sqlite</param>
 void SetReturnValue(IntPtr context, object r)
 {
     if (r is Exception)
     {
         Native.sqlite3_result_error16(context, ((Exception)r).Message, -1);
     }
     else
     {
         var o = SqliteUtils.ToDbFormat(r);
         if (o == null)
         {
             Native.sqlite3_result_null(context);
         }
         else if (r is int || r is uint)
         {
             Native.sqlite3_result_int(context, (int)r);
         }
         else if (r is long || r is ulong)
         {
             Native.sqlite3_result_int64(context, (long)r);
         }
         else if (r is double || r is float)
         {
             Native.sqlite3_result_double(context, (double)r);
         }
         else if (r is string)
         {
             string str = (string)r;
             // -1 for the last arg is the TRANSIENT destructor type so that sqlite will make its own copy of the string
             Native.sqlite3_result_text16(context, str, str.Length * 2, (IntPtr)(-1));
         }
         else if (r is byte[])
         {
             var bytes = (byte[])r;
             Native.sqlite3_result_blob(context, bytes, bytes.Length, (IntPtr)(-1));
         }
     }
 }
Ejemplo n.º 4
0
        public Statement Bind(params object [] vals)
        {
            Reset();

            if (vals == null && ParameterCount == 1)
            {
                vals = null_val;
            }

            if (vals == null || vals.Length != ParameterCount || ParameterCount == 0)
            {
                throw new ArgumentException("vals", string.Format("Statement has {0} parameters", ParameterCount));
            }

            for (int i = 1; i <= vals.Length; i++)
            {
                object o = SqliteUtils.ToDbFormat(vals[i - 1]);

                int code;
                if (o == null)
                {
                    code = Native.sqlite3_bind_null(Ptr, i);
                }
                else if (o is double)
                {
                    code = Native.sqlite3_bind_double(Ptr, i, (double)o);
                }
                else if (o is float)
                {
                    code = Native.sqlite3_bind_double(Ptr, i, (double)(float)o);
                }
                else if (o is int)
                {
                    code = Native.sqlite3_bind_int(Ptr, i, (int)o);
                }
                else if (o is uint)
                {
                    code = Native.sqlite3_bind_int(Ptr, i, (int)(uint)o);
                }
                else if (o is long)
                {
                    code = Native.sqlite3_bind_int64(Ptr, i, (long)o);
                }
                else if (o is ulong)
                {
                    code = Native.sqlite3_bind_int64(Ptr, i, (long)(ulong)o);
                }
                else if (o is byte[])
                {
                    byte[] bytes = o as byte[];
                    code = Native.sqlite3_bind_blob(Ptr, i, bytes, bytes.Length, (IntPtr)(-1));
                }
                else
                {
                    // C# strings are UTF-16, so 2 bytes per char
                    // -1 for the last arg is the TRANSIENT destructor type so that sqlite will make its own copy of the string
                    string str = (o as string) ?? o.ToString();
                    code = Native.sqlite3_bind_text16(Ptr, i, str, str.Length * 2, (IntPtr)(-1));
                }

                CheckError(code);
            }

            bound = true;
            return(this);
        }
Ejemplo n.º 5
0
        public object GetValue(object target)
        {
            object result = GetRawValue(target);

            return(SqliteUtils.ToDbFormat(type, result));
        }