Ejemplo n.º 1
0
        private void UpdateTableMapWithColumnInformation(TableMap map)
        {
            SqlResult sr = broker.Execute(String.Format(selectColumns, map.TableName), null, null);

            // process result set using columns: cid, name, type, notnull, dflt_value, pk
            for (int i = 0; i < sr.RowsContained; i++)
            {
                string   columnName = sr.GetString(i, "name");
                FieldMap fm         = map.GetFieldMapFromColumn(columnName);
                if (fm == null)
                {
                    fm = new FieldMap(map, columnName);
                    map.Fields.Add(fm);
                }
                // get basic column information
                fm.SetDbType(sr.GetString(i, "type"), false);
                fm.SetIsNullable(!sr.GetBoolean(i, "notnull"));
                fm.SetIsPrimaryKey(sr.GetBoolean(i, "pk"));
                fm.SetIsAutoGenerated(fm.IsPrimaryKey && (fm.Type == typeof(int) || fm.Type == typeof(long)));
            }
        }
Ejemplo n.º 2
0
        private void GetColumnData(TableMap map)
        {
            string       sql  = String.Format(selectColumns, map.TableName);
            SqlStatement stmt = broker.GetStatement(sql);

            stmt.StatementType = StatementType.Select;
            SqlResult sr = stmt.Execute();

            for (int i = 0; i < sr.Rows.Count; i++)
            {
                // returns columns: Field, Type, TypeSize, FieldSize, NotNull, HasDefault, Default
                string columnName = sr.GetString(i, "field");
                // get or create FieldMap for column
                FieldMap fm = map.GetFieldMapFromColumn(columnName);
                if (fm == null)
                {
                    fm = new FieldMap(map, columnName);
                    map.Fields.Add(fm);
                }
                bool isNullable = sr.GetString(i, "notnull").Trim().ToLower().StartsWith("f");
                if (fm != null)
                {
                    bool hasDefault = sr.GetBoolean(i, "hasdefault");
                    fm.SetDbType(sr.GetString(i, "type"), false);
                    int size = ExtractSize(sr.GetInt(i, "typesize"), sr.GetInt(i, "fieldsize"));
                    fm.SetSize(size);
                    fm.SetIsNullable(isNullable);
                    //fm.SetIsPrimaryKey( sr.GetString( i, "Key" ).Equals( "PRI" ) );
                    // fm.SetIsForeignKey( sr.GetString( i, "Key" ).Equals( "FOR" ) );
                    //if( fm.IsPrimaryKey )
                    //	fm.SetIsAutoGenerated( sr.GetString( i, "Key" ).Equals( "auto_increment" ) );
                    //if( sr.GetString( i, "HasDefault" ).Equals( "t" ) )
                    //	fm.SetMagicValue( sr.GetObject( i, "Default" ) );
                }
            }
        }