Schema tutorial

Created by: Giles Westwood, Last modification: 18 Nov 2005 (17:28 UTC) by Stephan Borg
packagename/admin/schema_inc.php contain adodb syntax for creating the packages database, this doc describes the syntax.
adodbsyntax

If anyone is interested, there is experimental code in /install/migrate_database.php which will try and convert a connect database to AdoDB DataDict syntax - the same used in schema_inc.php.

Not sure if the people at AdoDB would find it useful - but anyone converting a database schema by hand will definitely find it valuable.

Stephan aka wolff_borg



<?php
    
// iterate through source tables
    
foreach($tables_src as $table) {
...
        
$schema $gDb_src->MetaColumns$tablefalsetrue );
        
$t "";
        
$first true;
        foreach(
array_keys($schema) as $col) {
            
$t .= (!$first) ? ",\n" "";
            
$x $schema[$col];
            
$t .= $x->name " ";
            switch(
$x->type) {
                case 
"int":
                    
$i abs(( ( (int)$x->max_length 2) - ));
                    
$i = ($i == 5) ? $i;
                    
$i = ($i == 0) ? $i;
                    
$t .= "I" $i;
                    break;

                case 
"varchar":
                case 
"char":
                    
$t .= "C(" $x->max_length ")";
                    break;

                case 
"datetime":
                    
$t .= "T";
                    break;

                case 
"longblob":
                case 
"text":
                    
$t .= "X";
                    break;

                default:
                    die(
$x->type);
            }
            
$default = (!$x->binary) ? $x->has_default false;
            
$t .= " " . ( ($x->unsigned) ? "UNSIGNED" "" ) . " "
                 
. ( ($x->not_null) ? "NOTNULL" "" ) . " "
                 
. ( ($x->auto_increment) ? "AUTO" "" ) . " "
                
. ( ($x->primary_key) ? "PRIMARY" "" ) . " "
                
. ( ($default) ? "DEFAULT "$x->default_value "" );
            
$table_schema[$table] = $t;
            
$first false;
        }
        
$indices[$table] = $gDb_src->MetaIndexes$tablefalsefalse );
    }
?>

Related Items

Documentation » Tutorials

Tutorials to help you work out how something in bitweaver is done

  •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •    •  Anonymous  •  Array  •  Array  •  Array