Changeset 922

Show
Ignore:
Timestamp:
10/02/05 10:44:37 (3 years ago)
Author:
mbonetti
Message:

Fix for #77. The schema can now be built like this:

php schema.php -- --dump --prefix=table_prefix

(the prefix argument being optional)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/rss/schema.php

    r878 r922  
    8787} 
    8888 
     89function rss_query_wrapper($query, $dieOnError=true, $preventRecursion=false) { 
     90    if (defined('DUMP_SCHEMA')) { 
     91        echo $query . ";\n"; 
     92    } else { 
     93        rss_query($query,$dieOnError,$preventRecursion); 
     94    } 
     95} 
    8996 
    9097/** 
     
    145152function _init_channels() { 
    146153    $table = getTable('channels'); 
    147     rss_query ('DROP TABLE IF EXISTS ' . $table, true, true); 
     154    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); 
    148155    $sql_create = str_replace('__table__',$table, <<< _SQL_ 
    149156        CREATE TABLE __table__ ( 
     
    163170); 
    164171 
    165     rss_query($sql_create, false, true); 
     172    rss_query_wrapper($sql_create, false, true); 
    166173    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    167174        rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     
    176183function _init_folders() { 
    177184    $table = getTable('folders'); 
    178     rss_query ('DROP TABLE IF EXISTS ' . $table, true, true); 
     185    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); 
    179186    $sql_create = str_replace('__table__',$table, <<< _SQL_ 
    180187        CREATE TABLE __table__ ( 
     
    188195); 
    189196 
    190     rss_query($sql_create, false, true); 
    191     if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    192         rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
    193         return 0; 
    194     } 
    195      
    196      
    197     rss_query ("INSERT INTO $table (id,name) VALUES (0,'')", false, true); 
     197    rss_query_wrapper($sql_create, false, true); 
     198    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
     199        rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     200        return 0; 
     201    } 
     202     
     203     
     204    rss_query_wrapper ("INSERT INTO $table (id,name) VALUES (0,'')", false, true); 
    198205    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    199206        rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR); 
    200207        return 0; 
    201208    } 
    202     rss_query ("update $table set id=0 where id=1", false, true); 
     209    rss_query_wrapper ("update $table set id=0 where id=1", false, true); 
    203210    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    204211        rss_error('The '  . $table .  ' table was created successfully, but I couldn\'t insert the default values. Please do so manually!', RSS_ERROR_ERROR); 
     
    215222    $cfg_table = getTable('config'); 
    216223     
    217     rss_query ('DROP TABLE IF EXISTS ' . $cfg_table, true, true); 
     224    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $cfg_table, true, true); 
    218225     
    219226    $sql_create = str_replace('__config__',$cfg_table, <<< _SQL_ 
     
    230237); 
    231238 
    232     rss_query($sql_create, false, true); 
     239    rss_query_wrapper($sql_create, false, true); 
    233240    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    234241        rss_error('The ' .getTable('config') . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     
    287294        $ds=rss_real_escape_string($ds); 
    288295        $e=rss_real_escape_string($e); 
    289         rss_query('insert into '. getTable('config')  
     296        rss_query_wrapper('insert into '. getTable('config')  
    290297            . "(key_,value_,default_,type_,desc_,export_) VALUES (" 
    291298            . "'$k','$v','$d','$t','$ds'," .($e?"'$e'":"null") .")",false,true); 
     
    303310function _init_item() { 
    304311    $table = getTable('item'); 
    305     rss_query ('DROP TABLE IF EXISTS ' . $table, true, true); 
     312    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); 
    306313    $sql_create = str_replace('__table__',$table, <<< _SQL_ 
    307314        CREATE TABLE __table__ ( 
     
    322329); 
    323330 
    324     rss_query($sql_create, false, true); 
     331    rss_query_wrapper($sql_create, false, true); 
    325332    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    326333        rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     
    335342function _init_tag() { 
    336343    $table = getTable('tag'); 
    337     rss_query ('DROP TABLE IF EXISTS ' . $table, true, true); 
     344    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); 
    338345    $sql_create = str_replace('__table__',$table, <<< _SQL_ 
    339346        CREATE TABLE __table__ ( 
     
    347354); 
    348355 
    349     rss_query($sql_create, false, true); 
     356    rss_query_wrapper($sql_create, false, true); 
    350357    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    351358        rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     
    361368function _init_metatag() { 
    362369    $table = getTable('metatag'); 
    363     rss_query ('DROP TABLE IF EXISTS ' . $table, true, true); 
     370    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); 
    364371    $sql_create = str_replace('__table__',$table, <<< _SQL_ 
    365372        CREATE TABLE __table__ ( 
     
    374381); 
    375382 
    376     rss_query($sql_create, false, true); 
     383    rss_query_wrapper($sql_create, false, true); 
    377384    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    378385        rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     
    387394function _init_rating() { 
    388395    $table = getTable('rating'); 
    389     rss_query ('DROP TABLE IF EXISTS ' . $table, true, true); 
     396    rss_query_wrapper ('DROP TABLE IF EXISTS ' . $table, true, true); 
    390397    $sql_create = str_replace('__table__',$table, <<< _SQL_ 
    391398        CREATE TABLE __table__ ( 
     
    396403); 
    397404 
    398     rss_query($sql_create, false, true); 
     405    rss_query_wrapper($sql_create, false, true); 
    399406    if (!rss_is_sql_error(RSS_SQL_ERROR_NO_ERROR)) { 
    400407        rss_error('The ' . $table . 'table doesn\'t exist and I couldn\'t create it! Please create it manually.', RSS_ERROR_ERROR); 
     
    406413 
    407414 
    408  
     415if (isset($argv) && in_array('--dump',$argv)) { 
     416    foreach ($argv as $idx => $arg) { 
     417        if (substr($arg,0,9) == '--prefix=') { 
     418            define ('DB_TABLE_PREFIX',substr($arg,9)); 
     419        } 
     420    } 
     421    require_once('init.php'); 
     422    define ('DUMP_SCHEMA', true); 
     423     
     424    foreach (array("channels","config","folders","item","metatag","tag","rating") as $tbl) { 
     425        call_user_func("_init_$tbl");  
     426    } 
     427         
     428         
     429} 
    409430 
    410431?>