lwicks has asked for the wisdom of the Perl Monks concerning the following question:
sub create_ladder_data { # This sub creates the db datafiles for a ladder + tournament # Basically it creates database tables. print p("Start of createladder_data") if $DEBUG; # Collect the data from the passed array and the +n grap the variables we will need # ---------------------------------------------- +---------------------------------- my @the_shiai_data = @_; # T +his is the data transfered to us my $shiai_ID = $the_shiai_data[1]; # A + scaler to carry the id of this new shiai, used for nameing that data + tables. # create the scalers we need to use in the sql # ---------------------------------------------- my $ladder_table = "data/shiai_data/" . $shiai_I +D . ".ldr"; # eg: data/shiai_data/userTest.ldr the ladder itself my $ladder_table_fields = "player_name,ID,positi +on,fights,wins,joined_date,date_last_fight"; # These are the fields + for the userTest.ldr file print p(" table fields = ", $ladder_table_fields + ) if $DEBUG; my $history_table = "data/shiai_data/" . $shiai_ +ID . ".hst"; # eg: data/shiai_data/userTest.hst the history file +for this shiai my $challenge_table = "data/shiai_data/" . $shia +i_ID . ".chl"; # eg: data/shiai_data/userTest.chl the repository +for the challenges # Okay now we must create the database files (th +ree) # here is the DBI/SQL code # ---------------------------------------------- +------ my $dbh = DBI->connect('dbi:AnyData(RaiseError=> +1):'); # tell DBI we want to use the Anydata module in ./MyLibs # my $sql_command = "CREATE TABLE ? ( ?,?,?,?,?, +?,?,? )"; # my @sql_parameters = ($ladder_table, @ladder_ta +ble_fields); # print "$sql_command\n[@sql_parameters]\n" if $D +EBUG; # my $sql_handle = $dbh->prepare( $sql_command ); # $sql_handle->execute ( @sql_parameters); $dbh->do("CREATE TABLE $ladder_table ( $ladder_t +able_fields )"); # $dbh->func( 'shiai_db', 'CSV', 'data/shiai.csv' +, 'ad_catalog'); # Connect to the users.csv data file # select from the datafile the id for the user I +D from the array paased from the previous sub routine # my $sql = "SELECT * FROM shiai_db WHERE shiai_i +d = ?"; # this is the SQL command we want to execute # my $params = ($entered_shiai_id); + # Theese are the parameteres we will use in the SQL comma +nd above # print "$sql\n[$params]\n" if $DEBUG; + # if we are in debug mode print the SQL statement # my $sth = $dbh->prepare( $sql ); + # prepare the SQL command # $sth->execute( $params ); + # excecute the SQL using our parameters # my @result = $sth->fetchrow_array; # this line +takes the results of the select and puts it in the array called RESUL +TS $dbh->disconnect(); # we are done with the datba +se for now, so disconnect from it (MAY NOT BE NECESSARY) print p("END of create_ladder_data") if $DEBUG; }
janitored by ybiC: Removed "please help" from title, balanced <readmore> tags around long codeblock, closed unbalanced <b> tag
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBD::ANYDATA create table help please.
by Roger (Parson) on Jan 28, 2004 at 00:55 UTC | |
by lwicks (Friar) on Jan 28, 2004 at 22:00 UTC | |
by Roger (Parson) on Jan 28, 2004 at 22:52 UTC | |
|
Re: DBD::ANYDATA create table help please.
by Ao (Friar) on Jan 27, 2004 at 23:52 UTC | |
by lwicks (Friar) on Jan 28, 2004 at 21:06 UTC | |
by lwicks (Friar) on Jan 28, 2004 at 21:15 UTC | |
|
Re: DBD::ANYDATA create table help please.
by jeremyh (Beadle) on Jan 28, 2004 at 00:25 UTC | |
by jeremyh (Beadle) on Jan 28, 2004 at 00:45 UTC | |
by Roger (Parson) on Jan 28, 2004 at 01:08 UTC | |
by jeremyh (Beadle) on Jan 28, 2004 at 19:29 UTC |