示例#1
0
 internal object GetValue(int i,Connection conn){
     if (IsDBNull(i,conn))
         return null;
     if (_tableFieldCounts.ContainsKey(i))
     {
         Table t = (Table)LazyProxy.Instance(_tableFields[_fieldNames[i]].GetConstructor(System.Type.EmptyTypes).Invoke(new object[0]));
         sTableField[] flds = conn.Pool.Mapping[_tableFields[_fieldNames[i]]].Fields;
         int index = 0;
         i = TranslateFieldIndex(i);
         foreach (sTableField fld in flds)
         {
             PropertyInfo pi = t.GetType().GetProperty(fld.ClassProperty, Utility._BINDING_FLAGS_WITH_INHERITANCE);
             if (!pi.PropertyType.IsArray || !pi.PropertyType.Equals(typeof(byte[])))
             {
                 if (conn.Pool.Mapping.IsMappableType(pi.PropertyType) && !Utility.IsEnum(pi.PropertyType))
                 {
                     if (!conn.IsDBNull(i + index))
                     {
                         if (t.GetField(pi.Name) == null)
                         {
                             Table tmp = (Table)LazyProxy.Instance(pi.PropertyType.GetConstructor(Type.EmptyTypes).Invoke(new object[0]));
                             tmp.LoadStatus = LoadStatus.Partial;
                             t.SetField(fld.Name, tmp);
                         }
                         Table tbl = (Table)t.GetField(pi.Name);
                         foreach (sTableField f in conn.Pool.Mapping[tbl.GetType()].Fields)
                         {
                             if (fld.ExternalField == f.Name)
                             {
                                 t.RecurSetPropertyValue(f.Name, conn, conn.GetName(i + index), tbl);
                                 index++;
                                 break;
                             }
                         }
                     }
                     else
                         index++;
                 }
                 else
                 {
                     if (!conn.IsDBNull(i + index))
                     {
                         if (Utility.IsEnum(pi.PropertyType))
                             t.SetField(fld.ClassProperty, conn.Pool.GetEnumValue(pi.PropertyType, conn.GetInt32(i + index)));
                         else
                             t.SetField(fld.ClassProperty, conn[i + index]);
                     }
                     index++;
                 }
             }
         }
         t.LoadStatus = LoadStatus.Complete;
         return t;
     }
     else if (_enumFields.ContainsKey(i))
     {
         return _pool.GetEnumValue(_enumFields[i], conn.GetInt32(TranslateFieldIndex(i)));
     }else
         return conn.GetValue(TranslateFieldIndex(i));
 }
示例#2
0
 internal bool IsDBNull(int i,Connection conn)
 {
     if (!_tableFieldCounts.ContainsKey(i))
         return conn.IsDBNull(TranslateFieldIndex(i));
     else
     {
         int start = TranslateFieldIndex(i);
         for (int x = 0; x < _tableFieldCounts[i]; x++)
         {
             if (!conn.IsDBNull(x + start))
                 return false;
         }
         return true;
     }
 }
示例#3
0
 public void Init(Connection conn)
 {
     _tables = new List<ExtractedTableMap>();
     _triggers = new List<Trigger>();
     _generators = new List<Generator>();
     _identities = new List<IdentityField>();
     _views = new List<View>();
     _procedures = new List<StoredProcedure>();
     _createdTypes = new List<Type>();
     conn.ExecuteQuery(conn.Pool.queryBuilder.SelectTriggers());
     while (conn.Read())
     {
         //patch to handle long trigger code from mssql
         if (_triggers.Count > 0)
         {
             if (_triggers[_triggers.Count - 1].Name == (string)conn[0])
                 _triggers[_triggers.Count - 1] = new Trigger((string)conn[0], (string)conn[1], _triggers[_triggers.Count - 1].Code + (string)conn[2]);
             else
                 _triggers.Add(new Trigger((string)conn[0], (string)conn[1], (string)conn[2]));
         }else
             _triggers.Add(new Trigger((string)conn[0], (string)conn[1], (string)conn[2]));
     }
     conn.Close();
     conn.ExecuteQuery(conn.Pool.queryBuilder.SelectProcedures());
     while (conn.Read())
     {
         _procedures.Add(new StoredProcedure(conn[0].ToString(), conn[1].ToString(), conn[2].ToString(), conn[3].ToString(), conn[4].ToString()));
     }
     conn.Close();
     conn.ExecuteQuery(conn.queryBuilder.SelectViews());
     while (conn.Read())
         _views.Add(new View((string)conn[0], (string)conn[1]));
     conn.Close();
     conn.ExecuteQuery(conn.queryBuilder.SelectTableNames());
     while (conn.Read())
     {
         _tables.Add(new ExtractedTableMap((string)conn[0]));
     }
     conn.Close();
     for (int x = 0; x < _tables.Count; x++)
     {
         ExtractedTableMap etm = _tables[x];
         etm.Indices = conn.queryBuilder.ExtractTableIndexes(etm.TableName, conn);
         conn.ExecuteQuery(conn.queryBuilder.SelectTableFields(etm.TableName));
         while (conn.Read())
         {
             etm.Fields.Add(new ExtractedFieldMap(conn[0].ToString(), conn[1].ToString(),
                                                  long.Parse(conn[2].ToString()), bool.Parse(conn[3].ToString()), bool.Parse(conn[4].ToString()),
                                                  bool.Parse(conn[5].ToString()),
                                                  (conn.IsDBNull(6) ? null : conn[6].ToString())));
         }
         conn.Close();
         conn.ExecuteQuery(conn.queryBuilder.SelectForeignKeys(etm.TableName));
         while (conn.Read())
         {
             etm.ForeignFields.Add(new ForeignRelationMap(conn[5].ToString(), conn[0].ToString(), conn[1].ToString(),
                                                          conn[2].ToString(), conn[3].ToString(), conn[4].ToString()));
         }
         conn.Close();
         _tables.RemoveAt(x);
         _tables.Insert(x, etm);
     }
     if (conn.UsesGenerators)
     {
         conn.ExecuteQuery(conn.queryBuilder.SelectGenerators());
         while (conn.Read())
         {
             _generators.Add(new Generator((string)conn[0]));
         }
         conn.Close();
         for (int x = 0; x < _generators.Count; x++)
         {
             Generator gen = _generators[x];
             conn.ExecuteQuery(conn.queryBuilder.GetGeneratorValue(gen.Name));
             conn.Read();
             gen.Value = long.Parse(conn[0].ToString());
             conn.Close();
             _generators.RemoveAt(x);
             _generators.Insert(x, gen);
         }
     }
     if (conn.UsesIdentities)
     {
         conn.ExecuteQuery(conn.queryBuilder.SelectIdentities());
         while (conn.Read())
         {
             _identities.Add(new IdentityField((string)conn[0], (string)conn[1], (string)conn[2], (string)conn[3]));
         }
         conn.Close();
     }
 }