Hi all, am still knocking away at my little Perl application and struggling with my ignorance of all things Perl and specifically to this post DBD::Anydata. I have written the following sub to create a table, but unsuprisingly it does not work. Can a monk of suitable wisdom help me out? The following code causes no error, it just stops and gives no errors. It does not create a table either. I look forward to your input. Lance

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; }

Kia Kaha, Kia Toa, Kia Manawanui!
Be Strong, Be Brave, Be perservering!

janitored by ybiC: Removed "please help" from title, balanced <readmore> tags around long codeblock, closed unbalanced <b> tag


In reply to DBD::ANYDATA create table by lwicks

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.