Beispiel #1
0
        static public string GetDBAttributes(System.Reflection.FieldInfo info)
        {
            string attributes = "";

            if (s_Attributes.Count == 0)
            {
                Init();
            }
            HashSet <string> xorAttributesName = new HashSet <string>();

            foreach (string name in s_AttributesName)
            {
                if (attributes.Length > 0)
                {
                    attributes += " ";
                }
                attributes += name;
                xorAttributesName.Add(name);
            }

            foreach (Attribute att in info.GetCustomAttributes(true))
            {
                if (s_Attributes.Contains(att.GetType()))
                {
                    DBFieldAttribute dbAtt = att as DBFieldAttribute;
                    xorAttributesName.Remove(dbAtt.GetKeyWord());
                }
            }
            foreach (string name in xorAttributesName)
            {
                attributes = attributes.Replace(name, "");
            }
            return(attributes);
        }
Beispiel #2
0
 public FieldInfo GetPrimaryKey(FieldInfo[] fields)
 {
     foreach (FieldInfo field in fields)
     {
         string attributes = DBFieldAttribute.GetDBAttributes(field);
         if (attributes.IndexOf(PRIMARY_KEY.Key) >= 0)
         {
             return(field);
         }
     }
     return(null);
 }
Beispiel #3
0
        public Dictionary <string, ColumnInfo> GetDBTableColumnsInfo(string tableName)
        {
            string           q      = "SELECT sql FROM sqlite_master WHERE name='" + tableName + "'";
            SqliteDataReader reader = Read(q);

            if (!reader.Read())
            {
                return(null);
            }
            string tableQuery = reader.GetString(0);

            reader.Close();
            tableQuery = tableQuery.Replace("\"", "");
            tableQuery = tableQuery.Replace("`", "");
            tableQuery = tableQuery.Replace("'", "");
            tableQuery = tableQuery.Replace("\t", " ");
            tableQuery = tableQuery.Replace("\n", " ");


            int openIndex  = tableQuery.IndexOf('(');
            int closeIndex = tableQuery.IndexOf(')');

            string columnsStr = tableQuery.Substring(openIndex + 1, closeIndex - openIndex - 1);

            string[] columnsInfo = columnsStr.Split(',');

            Dictionary <string, ColumnInfo> columns = new Dictionary <string, ColumnInfo>();

            for (int i = 0; i < columnsInfo.Length; ++i)
            {
                string[]      column     = columnsInfo[i].Split(' ');
                List <string> columnInfo = new List <string>();
                for (int j = 0; j < column.Length; ++j)
                {
                    if (column[j] != "")
                    {
                        columnInfo.Add(column[j]);
                    }
                }

                ColumnInfo info = new ColumnInfo();
                info._name     = columnInfo[0];
                info._dataType = GetCTypeToSqlType(FindSqlTypeToCType(columnsInfo[i]));
                if (info._dataType.Length == 0)
                {
                    info._dataType = "TEXT";
                }
                info._attribute = DBFieldAttribute.FindStringInAttributes(columnsInfo[i]);
                columns.Add(info._name, info);
            }
            return(columns);
        }
Beispiel #4
0
        public Dictionary <string, ColumnInfo> GetTableColumnsInfo(System.Type table)
        {
            string tableName = table.Name;
            Dictionary <string, ColumnInfo> columns = new Dictionary <string, ColumnInfo> ();

            FieldInfo[] fields = table.GetFields();
            for (int i = 0; i < fields.Length; ++i)
            {
                string     attributes = DBFieldAttribute.GetDBAttributes(fields[i]);
                ColumnInfo c          = new ColumnInfo(fields[i].Name, GetCTypeToSqlType(fields[i].FieldType), attributes);
                columns.Add(c._name, c);
            }
            return(columns);
        }
Beispiel #5
0
        static public string GetQuery(MonoSQLiteManager dbManager, System.Type table)
        {
            Dictionary <string, ColumnInfo> columns = new Dictionary <string, ColumnInfo>();

            FieldInfo[] fields = table.GetFields();
            for (int i = 0; i < fields.Length; ++i)
            {
                string     attributes = DBFieldAttribute.GetDBAttributes(fields[i]);
                ColumnInfo c          = new ColumnInfo(fields[i].Name, dbManager.GetCTypeToSqlType(fields[i].FieldType), attributes);
                columns.Add(c._name, c);
            }

            return(GetQuery(dbManager, table.Name, columns));
        }