Exemplo n.º 1
0
        internal override string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            int    len;
            IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype16_interop(stmt._sqlite_stmt, index, out len);

            nAffinity = UnsafeNativeMethods.sqlite3_column_type_interop(stmt._sqlite_stmt, index);

            if (p != IntPtr.Zero)
            {
                return(ToString(p, len));
            }
            else
            {
                switch (nAffinity)
                {
                case TypeAffinity.Int64:
                    return("BIGINT");

                case TypeAffinity.Double:
                    return("DOUBLE");

                case TypeAffinity.Blob:
                    return("BLOB");

                default:
                    return("TEXT");
                }
            }
        }
 static SQLiteConvert()
 {
     SQLiteConvert.FallbackDefaultTypeName = string.Empty;
     SQLiteConvert.UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
     SQLiteConvert.OleAutomationEpochAsJulianDay = 2415018.5;
     SQLiteConvert.MinimumJd = SQLiteConvert.computeJD(DateTime.MinValue);
     SQLiteConvert.MaximumJd = SQLiteConvert.computeJD(DateTime.MaxValue);
     string[] strArrays = new string[] { "THHmmssK", "THHmmK", "HH:mm:ss.FFFFFFFK", "HH:mm:ssK", "HH:mmK", "yyyy-MM-dd HH:mm:ss.FFFFFFFK", "yyyy-MM-dd HH:mm:ssK", "yyyy-MM-dd HH:mmK", "yyyy-MM-ddTHH:mm:ss.FFFFFFFK", "yyyy-MM-ddTHH:mmK", "yyyy-MM-ddTHH:mm:ssK", "yyyyMMddHHmmssK", "yyyyMMddHHmmK", "yyyyMMddTHHmmssFFFFFFFK", "THHmmss", "THHmm", "HH:mm:ss.FFFFFFF", "HH:mm:ss", "HH:mm", "yyyy-MM-dd HH:mm:ss.FFFFFFF", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM-ddTHH:mm:ss.FFFFFFF", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss", "yyyyMMddHHmmss", "yyyyMMddHHmm", "yyyyMMddTHHmmssFFFFFFF", "yyyy-MM-dd", "yyyyMMdd", "yy-MM-dd" };
     SQLiteConvert._datetimeFormats     = strArrays;
     SQLiteConvert._datetimeFormatUtc   = SQLiteConvert._datetimeFormats[5];
     SQLiteConvert._datetimeFormatLocal = SQLiteConvert._datetimeFormats[19];
     SQLiteConvert._utf8 = new UTF8Encoding();
     Type[] typeArray = new Type[] { typeof(object), typeof(long), typeof(double), typeof(string), typeof(byte[]), typeof(object), typeof(DateTime), typeof(object) };
     SQLiteConvert._affinitytotype = typeArray;
     DbType[] dbTypeArray = new DbType[] { DbType.Object, DbType.Binary, DbType.Object, DbType.Boolean, DbType.SByte, DbType.SByte, DbType.Byte, DbType.Int16, DbType.UInt16, DbType.Int32, DbType.UInt32, DbType.Int64, DbType.UInt64, DbType.Single, DbType.Double, DbType.Decimal, DbType.DateTime, DbType.Object, DbType.String };
     SQLiteConvert._typetodbtype       = dbTypeArray;
     SQLiteConvert._dbtypetocolumnsize = new int[] { 2147483647, 2147483647, 1, 1, 8, 8, 8, 8, 8, 16, 2, 4, 8, 2147483647, 1, 4, 2147483647, 8, 2, 4, 8, 8, 2147483647, 2147483647, 2147483647, 2147483647 };
     object[] value = new object[] { DBNull.Value, DBNull.Value, 3, DBNull.Value, 19, DBNull.Value, DBNull.Value, 53, 53, DBNull.Value, 5, 10, 19, DBNull.Value, 3, 24, DBNull.Value, DBNull.Value, 5, 10, 19, 53, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value };
     SQLiteConvert._dbtypetonumericprecision = value;
     object[] objArray = new object[] { DBNull.Value, DBNull.Value, 0, DBNull.Value, 4, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, 0, 0, 0, DBNull.Value, 0, DBNull.Value, DBNull.Value, DBNull.Value, 0, 0, 0, 0, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value };
     SQLiteConvert._dbtypetonumericscale = objArray;
     Type[] typeArray1 = new Type[] { typeof(string), typeof(byte[]), typeof(byte), typeof(bool), typeof(decimal), typeof(DateTime), typeof(DateTime), typeof(decimal), typeof(double), typeof(Guid), typeof(short), typeof(int), typeof(long), typeof(object), typeof(sbyte), typeof(float), typeof(string), typeof(DateTime), typeof(ushort), typeof(uint), typeof(ulong), typeof(double), typeof(string), typeof(string), typeof(string), typeof(string) };
     SQLiteConvert._dbtypeToType = typeArray1;
     TypeAffinity[] typeAffinityArray = new TypeAffinity[] { TypeAffinity.Null, TypeAffinity.Blob, TypeAffinity.Null, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Int64, TypeAffinity.Double, TypeAffinity.Double, TypeAffinity.Double, TypeAffinity.DateTime, TypeAffinity.Null, TypeAffinity.Text };
     SQLiteConvert._typecodeAffinities = typeAffinityArray;
     SQLiteConvert._syncRoot           = new object();
     SQLiteConvert._typeNames          = null;
 }
Exemplo n.º 3
0
        public static SQLiteMappedColumnSet CreateColumnSetForType(Type classType)
        {
            SQLiteMappedColumnSet columnSet = new SQLiteMappedColumnSet();

            foreach (MemberInfo memberInfo in classType.GetMembers(
                         BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                Type         memberType;
                PropertyInfo propertyInfo = memberInfo as PropertyInfo;
                FieldInfo    fieldInfo    = memberInfo as FieldInfo;
                if (propertyInfo != null)
                {
                    memberType = propertyInfo.PropertyType;
                }
                else if (fieldInfo != null)
                {
                    memberType = fieldInfo.FieldType;
                }
                else
                {
                    continue;
                }

                SQLiteMapperPropertyAttribute attribute = null;
                foreach (Attribute baseAttribute in memberInfo.GetCustomAttributes(true))
                {
                    attribute = baseAttribute as SQLiteMapperPropertyAttribute;
                    if (attribute != null)
                    {
                        break;
                    }
                }
                if (attribute == null)
                {
                    continue;
                }

                TypeAffinity affinity = GetSQLiteAffinityForType(memberType);

                MappedColumn column = new MappedColumn(memberInfo.Name, memberType, affinity);
                column.PrimaryKey = attribute.PrimaryKey;

                bool nullable;
                if (attribute.Nullable == OptionalBool.Unspecified && memberType != typeof(SQLiteIdList))
                {
                    nullable = Nullable.GetUnderlyingType(memberType) != null;
                }
                else
                {
                    nullable = attribute.Nullable != OptionalBool.False;
                }

                column.Nullable        = nullable;
                column.SqlDefaultValue = attribute.SqlDefaultValue;

                columnSet.Columns.Add(column);
            }
            return(columnSet);
        }
Exemplo n.º 4
0
 public SQLite3ColumnDef(
     Func <TTable, TColumn> columnValueExtractor,
     string name,
     TypeAffinity typeAffinity,
     bool isNotNull = false,
     bool isPK      = false,
     bool isUnique  = false)
     : base(columnValueExtractor, name, GetTypeName(typeAffinity), isNotNull, isPK, isUnique)
 {
 }
Exemplo n.º 5
0
        /// <summary>
        /// Helper function to retrieve a column of data from an active statement.
        /// </summary>
        /// <param name="stmt">The statement being step()'d through</param>
        /// <param name="index">The column index to retrieve</param>
        /// <param name="typ">The type of data contained in the column.  If Uninitialized, this function will retrieve the datatype information.</param>
        /// <returns>Returns the data in the column</returns>
        internal override object GetValue(SqliteStatement stmt, int index, SQLiteType typ)
        {
            if (IsNull(stmt, index))
            {
                return(DBNull.Value);
            }
            TypeAffinity aff = typ.Affinity;
            Type         t   = null;

            if (typ.Type != DbType.Object)
            {
                t   = SQLiteTypeToType(typ);
                aff = TypeToAffinity(t);
            }

            switch (aff)
            {
            case TypeAffinity.Blob:
                if (typ.Type == DbType.Guid && typ.Affinity == TypeAffinity.Text)
                {
                    return(new Guid(GetText(stmt, index)));
                }

                var n = (int)GetBytes(stmt, index, 0, null, 0, 0);
                var b = new byte[n];
                GetBytes(stmt, index, 0, b, 0, n);

                if (typ.Type == DbType.Guid && n == 16)
                {
                    return(new Guid(b));
                }

                return(b);

            case TypeAffinity.DateTime:
                return(GetDateTime(stmt, index));

            case TypeAffinity.Double:
                if (t == null)
                {
                    return(GetDouble(stmt, index));
                }
                return(Convert.ChangeType(GetDouble(stmt, index), t, null));

            case TypeAffinity.Int64:
                if (t == null)
                {
                    return(GetInt64(stmt, index));
                }
                return(Convert.ChangeType(GetInt64(stmt, index), t, null));

            default:
                return(GetText(stmt, index));
            }
        }
Exemplo n.º 6
0
        private static string GetTypeName(TypeAffinity typeAffinity)
        {
            switch (typeAffinity)
            {
            case TypeAffinity.Int64:
                return("integer");

            default:
                return(Enum.GetName(typeof(TypeAffinity), typeAffinity));
            }
        }
Exemplo n.º 7
0
 public void SQL3SqlvarTid()
 {
     SqlType        = Sql3Type.SQL3TYPE_ROWID;
     DataSourceType = "SQL3TYPE_ROWID";
     SqlLen         = SqliteConstants.SQL3_ROWID_LEN_EXTERNAL;
     typeAffinity   = TypeAffinity.TYPE_AFFINITY_INTEGER;
     NullIndicator  = 0;
     PartOfDateTime = SqliteConstants.NORMAL_OF_DATETIME;
     IsBlob         = false;
     SqlName        = SqliteConstants.SQL3_ROWID_ST_A;
 }
Exemplo n.º 8
0
        static void ReturnValue(IntPtr context, object result)
        {
            if (result == null || result == DBNull.Value)
            {
                _sqlite3_ReturnNull.Invoke(_sqlite3, new object[] { context });
                return;
            }

            Type t = result.GetType();

            if (t == typeof(DateTime))
            {
                object str = _sqlite3_ToString.InvokeSqlite(result);
                _sqlite3_ReturnText.InvokeSqlite(context, str);
                return;
            }
            else
            {
                Exception r = result as Exception;
                if (r != null)
                {
                    _sqlite3_ReturnError.InvokeSqlite(context, r.Message);
                    return;
                }
            }
            TypeAffinity resultAffinity = (TypeAffinity)_sqliteConvert_TypeToAffinity.InvokeSqlite(t);

            switch (resultAffinity)
            {
            case TypeAffinity.Null:
                _sqlite3_ReturnNull.InvokeSqlite(context);
                return;

            case TypeAffinity.Int64:
                _sqlite3_ReturnInt64.InvokeSqlite(context, Convert.ToInt64(result));
                return;

            case TypeAffinity.Double:
                _sqlite3_ReturnDouble.InvokeSqlite(context, Convert.ToDouble(result));
                return;

            case TypeAffinity.Text:
                _sqlite3_ReturnText.InvokeSqlite(context, result.ToString());
                return;

            case TypeAffinity.Blob:
                _sqlite3_ReturnBlob.InvokeSqlite(context, (byte[])result);
                return;
            }
        }
Exemplo n.º 9
0
        internal override object GetValue(SQLiteStatement stmt, int index, SQLiteType typ)
        {
            if (this.IsNull(stmt, index))
            {
                return(DBNull.Value);
            }
            TypeAffinity affinity = typ.Affinity;
            Type         type     = null;

            if (typ.Type != DbType.Object)
            {
                type     = SQLiteConvert.SQLiteTypeToType(typ);
                affinity = SQLiteConvert.TypeToAffinity(type);
            }
            switch (affinity)
            {
            case TypeAffinity.Int64:
                if (type != null)
                {
                    return(Convert.ChangeType(this.GetInt64(stmt, index), type, null));
                }
                return(this.GetInt64(stmt, index));

            case TypeAffinity.Double:
                if (type != null)
                {
                    return(Convert.ChangeType(this.GetDouble(stmt, index), type, null));
                }
                return(this.GetDouble(stmt, index));

            case TypeAffinity.Blob:
                if ((typ.Type != DbType.Guid) || (typ.Affinity != TypeAffinity.Text))
                {
                    int    nLength = (int)this.GetBytes(stmt, index, 0, null, 0, 0);
                    byte[] bDest   = new byte[nLength];
                    this.GetBytes(stmt, index, 0, bDest, 0, nLength);
                    if ((typ.Type == DbType.Guid) && (nLength == 0x10))
                    {
                        return(new Guid(bDest));
                    }
                    return(bDest);
                }
                return(new Guid(this.GetText(stmt, index)));

            case TypeAffinity.DateTime:
                return(this.GetDateTime(stmt, index));
            }
            return(this.GetText(stmt, index));
        }
Exemplo n.º 10
0
        internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            lock (dbLock) {
                string result = null;
                nAffinity = TypeAffinity.Text;

                if (stmt != null && stmt._sqlite_stmt != null)
                {
                    result    = stmt._sqlite_stmt.DataType(index).ToString();
                    nAffinity = SqliteConvert.TypeToAffinity(SqliteConvert.DbTypeToType(SqliteConvert.TypeNameToDbType(result)));
                }

                return(result);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns the column as a Guid
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>Guid</returns>
        public override Guid GetGuid(int i)
        {
            TypeAffinity affinity = VerifyType(i, DbType.Guid);

            if (affinity == TypeAffinity.Blob)
            {
                byte[] buffer = new byte[16];
                _activeStatement._sql.GetBytes(_activeStatement, i, 0, buffer, 0, 16);
                return(new Guid(buffer));
            }
            else
            {
                return(new Guid(_activeStatement._sql.GetText(_activeStatement, i)));
            }
        }
Exemplo n.º 12
0
        internal override TypeAffinity ColumnAffinity(SqliteStatement stmt, int index)
        {
            lock (dbLock) {
                TypeAffinity result = TypeAffinity.Text;

                if (stmt != null && stmt._sqlite_stmt != null)
                {
                    result = SqliteConvert.TypeToAffinity(
                        SqliteConvert.DbTypeToType(
                            SqliteConvert.TypeNameToDbType(
                                stmt._sqlite_stmt.DataType(index).ToString())));
                }

                return(result);
            }
        }
Exemplo n.º 13
0
        internal override string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            int    num;
            IntPtr nativestring = UnsafeNativeMethods.sqlite3_column_decltype_interop((IntPtr)stmt._sqlite_stmt, index, out num);

            nAffinity = this.ColumnAffinity(stmt, index);
            if (nativestring != IntPtr.Zero)
            {
                return(SQLiteConvert.UTF8ToString(nativestring, num));
            }
            string[] typeDefinitions = stmt.TypeDefinitions;
            if (((typeDefinitions != null) && (index < typeDefinitions.Length)) && (typeDefinitions[index] != null))
            {
                return(typeDefinitions[index]);
            }
            return(string.Empty);
        }
Exemplo n.º 14
0
        static object[] PrepareParameters(int nArgs, IntPtr argptr)
        {
            object[] parms  = new object[nArgs];
            int[]    argint = new int[nArgs];
            Marshal.Copy(argptr, argint, 0, nArgs);
            for (int n = 0; n < nArgs; n++)
            {
                TypeAffinity affinity = (TypeAffinity)_sqlite3_GetParamValueType.InvokeSqlite((IntPtr)argint [n]);
                switch (affinity)
                {
                case TypeAffinity.Null:
                    parms [n] = DBNull.Value;
                    break;

                case TypeAffinity.Int64:
                    parms [n] = _sqlite3_GetParamValueInt64.InvokeSqlite((IntPtr)argint [n]);
                    break;

                case TypeAffinity.Double:
                    parms [n] = _sqlite3_GetParamValueDouble.InvokeSqlite((IntPtr)argint [n]);
                    break;

                case TypeAffinity.Text:
                    parms [n] = _sqlite3_GetParamValueText.InvokeSqlite((IntPtr)argint [n]);
                    break;

                case TypeAffinity.Blob:
                    int    x;
                    byte[] blob;
                    x    = (int)_sqlite3_GetParamValueBytes.InvokeSqlite((IntPtr)argint [n], 0, null, 0, 0);
                    blob = new byte[x];
                    _sqlite3_GetParamValueBytes.InvokeSqlite((IntPtr)argint [n], 0, blob, 0, 0);
                    parms [n] = blob;
                    break;

                case TypeAffinity.DateTime:
                    object text = _sqlite3_GetParamValueText.InvokeSqlite((IntPtr)argint [n]);
                    parms [n] = _sqlite3_ToDateTime.InvokeSqlite(text);
                    break;
                }
            }
            return(parms);
        }
Exemplo n.º 15
0
        private static string GetSQLiteAffinityName(TypeAffinity affinity)
        {
            switch (affinity)
            {
            case TypeAffinity.Blob:
            case TypeAffinity.Null:
            case TypeAffinity.Text:
                return("TEXT");

            case TypeAffinity.DateTime:
            case TypeAffinity.Int64:
                return("INTEGER");

            case TypeAffinity.Double:
                return("REAL");

            default:
                throw new ArgumentException("Invalid affinity: " + affinity.ToString());
            }
        }
        /// <summary>
        /// Returns the column as a Guid
        /// </summary>
        /// <param name="i">The index of the column to retrieve</param>
        /// <returns>Guid</returns>
        public override Guid GetGuid(int i)
        {
            if (i >= VisibleFieldCount && _keyInfo != null)
            {
                return(_keyInfo.GetGuid(i - VisibleFieldCount));
            }

            TypeAffinity affinity = VerifyType(i, DbType.Guid);

            if (affinity == TypeAffinity.Blob)
            {
                byte[] buffer = new byte[16];
                _activeStatement._sql.GetBytes(_activeStatement, i, 0, buffer, 0, 16);
                return(new Guid(buffer));
            }
            else
            {
                return(new Guid(_activeStatement._sql.GetText(_activeStatement, i)));
            }
        }
Exemplo n.º 17
0
        internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            int len;

#if !SQLITE_STANDARD
            IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype_interop(stmt._sqlite_stmt, index, out len);
#else
            len = -1;
            IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);
#endif
            nAffinity = ColumnAffinity(stmt, index);

            if (p != IntPtr.Zero)
            {
                return(UTF8ToString(p, len));
            }
            else
            {
                string[] ar = stmt.TypeDefinitions;
                if (ar != null)
                {
                    if (index < ar.Length && ar[index] != null)
                    {
                        return(ar[index]);
                    }
                }
                return(String.Empty);

                //switch (nAffinity)
                //{
                //  case TypeAffinity.Int64:
                //    return "BIGINT";
                //  case TypeAffinity.Double:
                //    return "DOUBLE";
                //  case TypeAffinity.Blob:
                //    return "BLOB";
                //  default:
                //    return "TEXT";
                //}
            }
        }
Exemplo n.º 18
0
        internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            var p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);

            nAffinity = ColumnAffinity(stmt, index);

            if (!string.IsNullOrEmpty(p))
            {
                return(UTF8ToString(p, -1));
            }

            string[] ar = stmt.TypeDefinitions;
            if (ar != null)
            {
                if (index < ar.Length && ar[index] != null)
                {
                    return(ar[index]);
                }
            }

            return(String.Empty);
        }
Exemplo n.º 19
0
 // not used
 static public string NativeTStr(TypeAffinity typeRef)
 {
     if (typeRef == TypeAffinity.Blob)
     {
         return("String");
     }
     else if (typeRef == TypeAffinity.DateTime)
     {
         return("DateTime");
     }
     else if (typeRef == TypeAffinity.Double)
     {
         return("Double");
     }
     else if (typeRef == TypeAffinity.Int64)
     {
         return("Int64");
     }
     else if (typeRef == TypeAffinity.None)
     {
         return("DBNull");
     }
     else if (typeRef == TypeAffinity.Null)
     {
         return("DBNull");
     }
     else if (typeRef == TypeAffinity.Uninitialized)
     {
         return("Empty");
     }
     else if (typeRef == TypeAffinity.Text)
     {
         return("String");
     }
     else
     {
         return("Empty");
     }
 }
Exemplo n.º 20
0
        internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);

            nAffinity = ColumnAffinity(stmt, index);

            if (p != IntPtr.Zero)
            {
                return(base.ToString(p));
            }
            else
            {
                string[] ar = stmt.TypeDefinitions;
                if (ar != null)
                {
                    if (index < ar.Length)
                    {
                        return(ar[index]);
                    }
                }

                switch (nAffinity)
                {
                case TypeAffinity.Int64:
                    return("BIGINT");

                case TypeAffinity.Double:
                    return("DOUBLE");

                case TypeAffinity.Blob:
                    return("BLOB");

                default:
                    return("TEXT");
                }
            }
        }
Exemplo n.º 21
0
        // not used
        static public System.TypeCode GetNativeType(TypeAffinity aff)
        {
            switch (aff)
            {
            case TypeAffinity.Text:
            case TypeAffinity.Blob:
                return(TypeCode.String);

            case TypeAffinity.DateTime:
                return(TypeCode.DateTime);

            case TypeAffinity.Double:
            case TypeAffinity.Int64:
                return(TypeCode.Double);

            case TypeAffinity.Null:
                return(TypeCode.DBNull);

            case TypeAffinity.Uninitialized:
            case TypeAffinity.None:
            default:
                return(TypeCode.Empty);
            }
        }
Exemplo n.º 22
0
 internal abstract string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity);
Exemplo n.º 23
0
 public SQLiteType(TypeAffinity affinity, DbType type) : this()
 {
     this.Affinity = affinity;
     this.Type     = type;
 }
Exemplo n.º 24
0
    internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity)
    {
      int len;
#if !SQLITE_STANDARD
      IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype_interop(stmt._sqlite_stmt, index, out len);
#else
      len = -1;
      IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);
#endif
      nAffinity = ColumnAffinity(stmt, index);

      if (p != IntPtr.Zero) return UTF8ToString(p, len);
      else
      {
        string[] ar = stmt.TypeDefinitions;
        if (ar != null)
        {
          if (index < ar.Length && ar[index] != null)
            return ar[index];
        }
        return String.Empty;

        //switch (nAffinity)
        //{
        //  case TypeAffinity.Int64:
        //    return "BIGINT";
        //  case TypeAffinity.Double:
        //    return "DOUBLE";
        //  case TypeAffinity.Blob:
        //    return "BLOB";
        //  default:
        //    return "TEXT";
        //}
      }
    }
Exemplo n.º 25
0
 internal abstract string ColumnType(SQLiteStatement stmt, int index, ref TypeAffinity nAffinity);
Exemplo n.º 26
0
        /// <summary>
        /// SQLite is inherently un-typed.  All datatypes in SQLite are natively strings.  The definition of the columns of a table
        /// and the affinity of returned types are all we have to go on to type-restrict data in the reader.
        ///
        /// This function attempts to verify that the type of data being requested of a column matches the datatype of the column.  In
        /// the case of columns that are not backed into a table definition, we attempt to match up the affinity of a column (int, double, string or blob)
        /// to a set of known types that closely match that affinity.  It's not an exact science, but its the best we can do.
        /// </summary>
        /// <returns>
        /// This function throws an InvalidTypeCast() exception if the requested type doesn't match the column's definition or affinity.
        /// </returns>
        /// <param name="i">The index of the column to type-check</param>
        /// <param name="typ">The type we want to get out of the column</param>
        private TypeAffinity VerifyType(int i, DbType typ)
        {
            CheckClosed();
            CheckValidRow();
            TypeAffinity affinity = _activeStatement._sql.ColumnAffinity(_activeStatement, i);

            switch (affinity)
            {
            case TypeAffinity.Int64:
                if (typ == DbType.Int16)
                {
                    return(affinity);
                }
                if (typ == DbType.Int32)
                {
                    return(affinity);
                }
                if (typ == DbType.Int64)
                {
                    return(affinity);
                }
                if (typ == DbType.Boolean)
                {
                    return(affinity);
                }
                if (typ == DbType.Byte)
                {
                    return(affinity);
                }
                break;

            case TypeAffinity.Double:
                if (typ == DbType.Single)
                {
                    return(affinity);
                }
                if (typ == DbType.Double)
                {
                    return(affinity);
                }
                if (typ == DbType.Decimal)
                {
                    return(affinity);
                }
                break;

            case TypeAffinity.Text:
                if (typ == DbType.SByte)
                {
                    return(affinity);
                }
                if (typ == DbType.String)
                {
                    return(affinity);
                }
                if (typ == DbType.SByte)
                {
                    return(affinity);
                }
                if (typ == DbType.Guid)
                {
                    return(affinity);
                }
                if (typ == DbType.DateTime)
                {
                    return(affinity);
                }
                break;

            case TypeAffinity.Blob:
                if (typ == DbType.Guid)
                {
                    return(affinity);
                }
                if (typ == DbType.String)
                {
                    return(affinity);
                }
                if (typ == DbType.Binary)
                {
                    return(affinity);
                }
                break;
            }

            throw new InvalidCastException();
        }
Exemplo n.º 27
0
        internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            var p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);
            nAffinity = ColumnAffinity(stmt, index);

            if (!string.IsNullOrEmpty(p))
            {
                return UTF8ToString(p, -1);
            }
            
            string[] ar = stmt.TypeDefinitions;
            if (ar != null)
            {
                if (index < ar.Length && ar[index] != null)
                    return ar[index];
            }

            return String.Empty;
        }
Exemplo n.º 28
0
 // not used
 static public string[] GetTypeNames()
 {
     return(TypeAffinity.GetNames(typeof(System.Data.SQLite.TypeAffinity)));
 }
Exemplo n.º 29
0
 private static string GetTypeName(TypeAffinity typeAffinity)
 {
     return(Enum.GetName(typeof(TypeAffinity), typeAffinity));
 }
Exemplo n.º 30
0
 internal abstract string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity);
Exemplo n.º 31
0
 public SQLiteFieldAffinity(TypeAffinity type, string columnName)
 {
     this.type       = type;
     this.columnName = columnName;
 }
Exemplo n.º 32
0
        internal override string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity)
        {
            int len;
              IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype16_interop(stmt._sqlite_stmt, index, out len);
              nAffinity = UnsafeNativeMethods.sqlite3_column_type_interop(stmt._sqlite_stmt, index);

              if (p != IntPtr.Zero) return ToString(p, len);
              else
              {
            switch (nAffinity)
            {
              case TypeAffinity.Int64:
            return "BIGINT";
              case TypeAffinity.Double:
            return "DOUBLE";
              case TypeAffinity.Blob:
            return "BLOB";
              default:
            return "TEXT";
            }
              }
        }
Exemplo n.º 33
0
        /// <summary>
        /// SQLite is inherently un-typed.  All datatypes in SQLite are natively strings.  The definition of the columns of a table
        /// and the affinity of returned types are all we have to go on to type-restrict data in the reader.
        ///
        /// This function attempts to verify that the type of data being requested of a column matches the datatype of the column.  In
        /// the case of columns that are not backed into a table definition, we attempt to match up the affinity of a column (int, double, string or blob)
        /// to a set of known types that closely match that affinity.  It's not an exact science, but its the best we can do.
        /// </summary>
        /// <returns>
        /// This function throws an InvalidTypeCast() exception if the requested type doesn't match the column's definition or affinity.
        /// </returns>
        /// <param name="i">The index of the column to type-check</param>
        /// <param name="typ">The type we want to get out of the column</param>
        private TypeAffinity VerifyType(int i, DbType typ)
        {
            CheckClosed();
            CheckValidRow();

#if UNITY_EDITOR
            TypeAffinity affinity = GetSQLiteType(i).Affinity;

            switch (affinity)
            {
            case TypeAffinity.Int64:
                if (typ == DbType.Int16)
                {
                    return(affinity);
                }
                if (typ == DbType.Int32)
                {
                    return(affinity);
                }
                if (typ == DbType.Int64)
                {
                    return(affinity);
                }
                if (typ == DbType.Boolean)
                {
                    return(affinity);
                }
                if (typ == DbType.Byte)
                {
                    return(affinity);
                }
                if (typ == DbType.DateTime)
                {
                    return(affinity);
                }
                if (typ == DbType.Single)
                {
                    return(affinity);
                }
                if (typ == DbType.Double)
                {
                    return(affinity);
                }
                if (typ == DbType.Decimal)
                {
                    return(affinity);
                }
                break;

            case TypeAffinity.Double:
                if (typ == DbType.Single)
                {
                    return(affinity);
                }
                if (typ == DbType.Double)
                {
                    return(affinity);
                }
                if (typ == DbType.Decimal)
                {
                    return(affinity);
                }
                if (typ == DbType.DateTime)
                {
                    return(affinity);
                }
                break;

            case TypeAffinity.Text:
                if (typ == DbType.SByte)
                {
                    return(affinity);
                }
                if (typ == DbType.String)
                {
                    return(affinity);
                }
                if (typ == DbType.SByte)
                {
                    return(affinity);
                }
                if (typ == DbType.Guid)
                {
                    return(affinity);
                }
                if (typ == DbType.DateTime)
                {
                    return(affinity);
                }
                if (typ == DbType.Decimal)
                {
                    return(affinity);
                }
                break;

            case TypeAffinity.Blob:
                if (typ == DbType.Guid)
                {
                    return(affinity);
                }
                if (typ == DbType.String)
                {
                    return(affinity);
                }
                if (typ == DbType.Binary)
                {
                    return(affinity);
                }
                break;
            }

            throw new InvalidCastException();
#else
            return(TypeAffinity.Uninitialized);
#endif
        }
Exemplo n.º 34
0
 public SQLite3ColumnDef(string name, TypeAffinity typeAffinity, bool isNotNull = false, bool isPK = false, bool isUnique = false)
     : base(name, GetTypeName(typeAffinity), isNotNull, isPK, isUnique)
 {
 }
Exemplo n.º 35
0
        private TypeAffinity VerifyType(int i, DbType typ)
        {
            this.CheckClosed();
            this.CheckValidRow();
            TypeAffinity affinity = this.GetSQLiteType(i).Affinity;

            switch (affinity)
            {
            case TypeAffinity.Int64:
                if (typ != DbType.Int16)
                {
                    if (typ != DbType.Int32)
                    {
                        if (typ == DbType.Int64)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.Boolean)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.Byte)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.DateTime)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.Single)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.Double)
                        {
                            return(affinity);
                        }
                        if (typ != DbType.Decimal)
                        {
                            break;
                        }
                    }
                    return(affinity);
                }
                return(affinity);

            case TypeAffinity.Double:
                if (typ != DbType.Single)
                {
                    if (typ != DbType.Double)
                    {
                        if (typ == DbType.Decimal)
                        {
                            return(affinity);
                        }
                        if (typ != DbType.DateTime)
                        {
                            break;
                        }
                    }
                    return(affinity);
                }
                return(affinity);

            case TypeAffinity.Text:
                if (typ != DbType.SByte)
                {
                    if (typ != DbType.String)
                    {
                        if (typ == DbType.SByte)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.Guid)
                        {
                            return(affinity);
                        }
                        if (typ == DbType.DateTime)
                        {
                            return(affinity);
                        }
                        if (typ != DbType.Decimal)
                        {
                            break;
                        }
                    }
                    return(affinity);
                }
                return(affinity);

            case TypeAffinity.Blob:
                if (typ != DbType.Guid)
                {
                    if (typ == DbType.String)
                    {
                        return(affinity);
                    }
                    if (typ == DbType.Binary)
                    {
                        return(affinity);
                    }
                    break;
                }
                return(affinity);
            }
            throw new InvalidCastException();
        }
        internal override string ColumnType(SqliteStatement stmt, int index, out TypeAffinity nAffinity) {
            lock (dbLock) {
                string result = null;
                nAffinity = TypeAffinity.Text;

                if (stmt != null && stmt._sqlite_stmt != null) {
                    result = stmt._sqlite_stmt.DataType(index).ToString();
                    nAffinity = SqliteConvert.TypeToAffinity(SqliteConvert.DbTypeToType(SqliteConvert.TypeNameToDbType(result)));
                }

                return result;
            }
        }