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 then grap the variables we will need # -------------------------------------------------------------------------------- my @the_shiai_data = @_; # This 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_ID . ".ldr"; # eg: data/shiai_data/userTest.ldr the ladder itself my $ladder_table_fields = "player_name,ID,position,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/" . $shiai_ID . ".chl"; # eg: data/shiai_data/userTest.chl the repository for the challenges # Okay now we must create the database files (three) # 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_table_fields); # print "$sql_command\n[@sql_parameters]\n" if $DEBUG; # my $sql_handle = $dbh->prepare( $sql_command ); # $sql_handle->execute ( @sql_parameters); $dbh->do("CREATE TABLE $ladder_table ( $ladder_table_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 ID from the array paased from the previous sub routine # my $sql = "SELECT * FROM shiai_db WHERE shiai_id = ?"; # this is the SQL command we want to execute # my $params = ($entered_shiai_id); # Theese are the parameteres we will use in the SQL command 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 RESULTS $dbh->disconnect(); # we are done with the datbase for now, so disconnect from it (MAY NOT BE NECESSARY) print p("END of create_ladder_data") if $DEBUG; }