lib/dbd/mysql/database.rb
#
# See DBI::BaseDatabase#columns.
#
# Extra attributes:
#
# * sql_type: XOPEN integer constant relating to type.
# * nullable: true if the column allows NULL as a value.
# * indexed: true if the column belongs to an index.
# * primary: true if the column is a part of a primary key.
# * unique: true if the values in this column are unique.
# * default: the default value if this column is not explicitly set. 
#


XOPEN integer constant relating to type.
nullable: true if the column allows NULL as a value.
indexed: true if the column belongs to an index.
primary: true if the column is a part of a primary key.
unique: true if the values in this column are unique.
default: the default value if this column is not explicitly set.
XOPEN integer constant relating to type . nullable : true if the column allows NULL as a value . indexed : true if the column belongs to an index . primary : true if the column is a part of a primary key . unique : true if the values in this column are unique . default : the default value if this column is not explicitly set .
def columns(table)
            dbh = DBI::DatabaseHandle.new(self)
            uniques = []
            dbh.execute("SHOW INDEX FROM #{table}") do |sth|
                sth.each do |row|
                    uniques << row[4] if row[1] == 0
                end
            end  
            ret = nil
            dbh.execute("SHOW FIELDS FROM #{table}") do |sth|
                ret = sth.collect do |row|
                    name, type, nullable, key, default, extra = row
                    sqltype, type, size, decimal = mysql_type_info(row[1])
                    col = Hash.new
                    col['name']           = name
                    col['sql_type']       = sqltype
                    col['type_name']      = type
                    col['nullable']       = nullable == "YES"
                    col['indexed']        = key != ""
                    col['primary']        = key == "PRI"
                    col['unique']         = uniques.index(name) != nil
                    col['precision']      = size
                    col['scale']          = decimal
                    col['default']        = row[4]
                    case col['type_name']
                    when 'timestamp'
                        col['dbi_type'] = DBI::Type::Timestamp
                    end
                    col
                end 
            end 
            ret
        end
def columns ( table ) dbh = DBI :: DatabaseHandle . new ( self ) uniques = [ ] dbh . execute ( "SHOW INDEX FROM #{table}" ) do | sth | sth . each do | row | uniques << row [ 4 ] if row [ 1 ] == 0 end end ret = nil dbh . execute ( "SHOW FIELDS FROM #{table}" ) do | sth | ret = sth . collect do | row | name , type , nullable , key , default , extra = row sqltype , type , size , decimal = mysql_type_info ( row [ 1 ] ) col = Hash . new col [ 'name' ] = name col [ 'sql_type' ] = sqltype col [ 'type_name' ] = type col [ 'nullable' ] = nullable == "YES" col [ 'indexed' ] = key != "" col [ 'primary' ] = key == "PRI" col [ 'unique' ] = uniques . index ( name ) != nil col [ 'precision' ] = size col [ 'scale' ] = decimal col [ 'default' ] = row [ 4 ] case col [ 'type_name' ] when 'timestamp' col [ 'dbi_type' ] = DBI :: Type :: Timestamp end col end end ret end
See DBI::BaseDatabase#columns.
See DBI :: BaseDatabase#columns .
#type = row[1] #size = type[type.index('(')+1..type.index(')')-1] #size = 0 #type = type[0..type.index('(')-1] # collect # execute
table
<not_specific>