# File lib/og/backends/mysql.rb, line 262
        def create_table(klass)
                fields = create_fields(klass, TYPEMAP)

                sql = "CREATE TABLE #{klass::DBTABLE} (#{fields.join(', ')}"
                
                # Create table constrains
                
                if klass.__meta and constrains = klass.__meta[:sql_constrain]
                        sql << ", #{constrains.join(', ')}"
                end
                
                sql << ');'
                
                begin
                        exec(sql)
                        Logger.info "Created table '#{klass::DBTABLE}'."
                rescue => ex
                        if ex.errno == 1050 # table already exists.
                                Logger.debug "Table already exists" if $DBG
                        else
                                raise
                        end
                end
                
                # Create indices
                
                if klass.__meta and indices = klass.__meta[:sql_index] 
                        for data in indices
                                idx, options = *data
                                idx = idx.to_s
                                pre_sql, post_sql = options[:pre], options[:post]
                                idxname = idx.gsub(/ /, "").gsub(/,/, "_").gsub(/\(.*\)/, "")
                                exec "CREATE #{pre_sql} INDEX #{klass::DBTABLE}_#{idxname}_idx #{post_sql} ON #{klass::DBTABLE} (#{idx})"  
                        end
                end

                # Create join tables if needed. Join tables are used in
                # 'many_to_many' relations.
                
                if klass.__meta and joins = klass.__meta[:sql_join] 
                        for data in joins
                                # the class to join to and some options.
                                join_class, options = *data
                                
                                # gmosx: dont use DBTABLE here, perhaps the join class
                                # is not managed yet.
                                join_table = "#{self.class.join_table(klass, join_class)}"
                                join_src = "#{self.class.encode(klass)}_oid"
                                join_dst = "#{self.class.encode(join_class)}_oid"
                                begin
                                        exec "CREATE TABLE #{join_table} ( key1 integer NOT NULL, key2 integer NOT NULL )"
                                        exec "CREATE INDEX #{join_table}_key1_idx ON #{join_table} (key1)"
                                        exec "CREATE INDEX #{join_table}_key2_idx ON #{join_table} (key2)"
                                rescue => ex
                                        if ex.errno == 1050 # table already exists.
                                                Logger.debug "Join table already exists" if $DBG
                                        else
                                                raise
                                        end
                                end
                        end
                end           
        end