Changeset 28262


Ignore:
Timestamp:
Aug 26, 2007, 10:52:22 PM (13 years ago)
Author:
jmpp@…
Message:

After a long time wihtout coming back to this, finally make the script work 100%!
(at least wrt populating the database ;-):

  • Remove the $dbcmdargs variable and pass each mysql arg separately to exec(n) at the end of the script, as the call doesn't work otherwise (without an eval in there at least);
  • semi-colon terminate each SQL statement written to the batch file (not too sure how the whole db populating thing was working without them!);
  • (sssshhhhhh! retab some tcl statements in the process);

This script is now operational and the only thing remaining to label it "production ready"
is some error catching and reporting, which I plan to implement through some macports1.0
UI initialization.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/base/portmgr/PortIndex2MySQL.tcl

    r27961 r28262  
    8383set dbcmd [macports::findBinary mysql5]
    8484set dbhost 127.0.0.1
    85 set dbname macports
    8685set dbuser macports
    8786set passwdfile [file join . password_file]
    8887set dbpasswd [getpasswd $passwdfile]
    89 set dbcmdargs "-h $dbhost -u $dbuser -p$dbpasswd $dbname"
     88set dbname macports
    9089
    9190# Flat text file to which sql statements are written.
     
    106105# Initial creation of database tables: log, portfiles, categories, maintainers, dependencies, variants and platforms.
    107106# Do we need any other?
    108 puts $sqlfile_fd "DROP TABLE log"
    109 puts $sqlfile_fd "CREATE TABLE IF NOT EXISTS log (activity VARCHAR(255), activity_time TIMESTAMP(14))"
    110 puts $sqlfile_fd "INSERT INTO log VALUES ('update', NOW())"
    111 
    112 puts $sqlfile_fd "DROP TABLE portfiles"
    113 puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT)"
    114 
    115 puts $sqlfile_fd "DROP TABLE IF EXISTS categories"
    116 puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER)"
    117 
    118 puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers"
    119 puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER)"
    120 
    121 puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies"
    122 puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255))"
    123 
    124 puts $sqlfile_fd "DROP TABLE IF EXISTS variants"
    125 puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255))"
    126 
    127 puts $sqlfile_fd "DROP TABLE IF EXISTS platforms"
    128 puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255))"
     107puts $sqlfile_fd "DROP TABLE IF EXISTS log;"
     108puts $sqlfile_fd "CREATE TABLE IF NOT EXISTS log (activity VARCHAR(255), activity_time TIMESTAMP(14));"
     109puts $sqlfile_fd "INSERT INTO log VALUES ('update', NOW());"
     110
     111puts $sqlfile_fd "DROP TABLE IF EXISTS portfiles;"
     112puts $sqlfile_fd "CREATE TABLE portfiles (name VARCHAR(255) PRIMARY KEY NOT NULL, path VARCHAR(255), version VARCHAR(255),  description TEXT);"
     113
     114puts $sqlfile_fd "DROP TABLE IF EXISTS categories;"
     115puts $sqlfile_fd "CREATE TABLE categories (portfile VARCHAR(255), category VARCHAR(255), is_primary INTEGER);"
     116
     117puts $sqlfile_fd "DROP TABLE IF EXISTS maintainers;"
     118puts $sqlfile_fd "CREATE TABLE maintainers (portfile VARCHAR(255), maintainer VARCHAR(255), is_primary INTEGER);"
     119
     120puts $sqlfile_fd "DROP TABLE IF EXISTS dependencies;"
     121puts $sqlfile_fd "CREATE TABLE dependencies (portfile VARCHAR(255), library VARCHAR(255));"
     122
     123puts $sqlfile_fd "DROP TABLE IF EXISTS variants;"
     124puts $sqlfile_fd "CREATE TABLE variants (portfile VARCHAR(255), variant VARCHAR(255));"
     125
     126puts $sqlfile_fd "DROP TABLE IF EXISTS platforms;"
     127puts $sqlfile_fd "CREATE TABLE platforms (portfile VARCHAR(255), platform VARCHAR(255));"
    129128
    130129
     
    190189        }
    191190
    192         puts $sqlfile_fd "INSERT INTO portfiles VALUES ('$portname', '$portdir', '$portversion', '$description')"
     191        puts $sqlfile_fd "INSERT INTO portfiles VALUES ('$portname', '$portdir', '$portversion', '$description');"
    193192
    194193        set primary 1
    195194        foreach category $categories {
    196                 set category [sql_escape $category]
    197                 puts $sqlfile_fd "INSERT INTO categories VALUES ('$portname', '$category', $primary)"
    198                 incr primary
     195            set category [sql_escape $category]
     196            puts $sqlfile_fd "INSERT INTO categories VALUES ('$portname', '$category', $primary);"
     197            incr primary
    199198        }
    200199       
    201200        set primary 1
    202201        foreach maintainer $maintainers {
    203                 set maintainer [sql_escape $maintainer]
    204                 puts $sqlfile_fd "INSERT INTO maintainers VALUES ('$portname', '$maintainer', $primary)"
    205                 incr primary
     202            set maintainer [sql_escape $maintainer]
     203            puts $sqlfile_fd "INSERT INTO maintainers VALUES ('$portname', '$maintainer', $primary);"
     204            incr primary
    206205        }
    207206
    208207        foreach build_dep $depends_build {
    209208            set build_dep [sql_escape $build_dep]
    210             puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$build_dep')"
     209            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$build_dep');"
    211210        }
    212211
    213212        foreach lib $depends_lib {
    214                 set lib [sql_escape $lib]
    215                 puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$lib')"
     213            set lib [sql_escape $lib]
     214            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$lib');"
    216215        }
    217216
    218217        foreach run_dep $depends_run {
    219218            set run_dep [sql_escape $run_dep]
    220             puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$run_dep')"
     219            puts $sqlfile_fd "INSERT INTO dependencies VALUES ('$portname', '$run_dep');"
    221220        }
    222221
    223222        foreach variant $variants {
    224                 set variant [sql_escape $variant]
    225                 puts $sqlfile_fd "INSERT INTO variants VALUES ('$portname', '$variant')"
     223            set variant [sql_escape $variant]
     224            puts $sqlfile_fd "INSERT INTO variants VALUES ('$portname', '$variant');"
    226225        }
    227226
    228227        foreach platform $platforms {
    229                 set platform [sql_escape $platform]
    230                 puts $sqlfile_fd "INSERT INTO platforms VALUES ('$portname', '$platform')"
     228            set platform [sql_escape $platform]
     229            puts $sqlfile_fd "INSERT INTO platforms VALUES ('$portname', '$platform');"
    231230        }
    232231
     
    240239    exit 1
    241240}
    242 if {[catch {exec $dbcmd $dbcmdargs <@ $sqlfile_fd} errstr]} {
     241if {[catch {exec -- $dbcmd --host=$dbhost --user=$dbuser --password=$dbpasswd --database=$dbname <@ $sqlfile_fd} errstr]} {
    243242    ui_error "${::errorCode}: $errstr"
    244243    exit 1
Note: See TracChangeset for help on using the changeset viewer.