If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Perl and the DBI > create table fails with large declaration

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-05, 17:39
squark squark is offline
Registered User
 
Join Date: Sep 2005
Posts: 2
Red face create table fails with large declaration

Greetings!

The following big command should be excuted:

Code:
CREATE TABLE inode( found_at DOUBLE, extent_offs DOUBLE, di_inostamp DOUBLE, di_fileset DOUBLE, di_otimetv_sec DOUBLE, di_number DOUBLE, di_gen DOUBLE, di_ixpxdlen DOUBLE, di_ixpxdaddr1 DOUBLE, di_ixpxdaddr2 DOUBLE, di_ixpxdaddress DOUBLE, di_size DOUBLE, di_nblocks DOUBLE, di_nlink DOUBLE, di_uid DOUBLE, di_gid DOUBLE, di_mode DOUBLE, di_atimetv_sec DOUBLE, di_ctimetv_sec DOUBLE, di_next_index DOUBLE, di_mtimetv_sec DOUBLE )
I could only get a new table, if I choped it to the first three fields or by typing it as string directly in the prepare command like this:

Code:
$sth = $dbh->prepare("CREATE TABLE inode( found_at DOUBLE, extent_offs DOUBLE, di_inostamp DOUBLE, di_fileset DOUBLE, di_otimetv_sec [...] )");
$sth->execute;   #this worked but is not what i need
$sth->finish;
But the hole point in using Perl here, is to be able to create various tables at runtime. To accomplish that, the string $tabdef needs to be autogenerated and should then be used as follows:

Code:
for ($j=0; $j<=3; $j++) {  #larger then 3 and it fails
    $tabdef = $tabdef." $column[$j] DOUBLE,";
}
$tabdef =~ s/,$//;
$tabdef =~ s/\.//g;   #no dots!
$tabdef = "CREATE TABLE inode(".$tabdef." )";
$dbh->do("DROP TABLE inode");
$sth = $dbh->prepare($tabdef) or die "Can't prepare $tabdef: $dbh->errstrn";
$sth->execute or die "Can't execute: $dbh->errstrn";
$sth->finish;
And this wont work. I have no idea why. The syntax is correct, bcoz when using it with only 3 fields its ok, otherwise I get the error message:

Code:
Can't execute: DBI::db=HASH(0x82bb848)->errstrn at ./tabulator.pl line 89.
Im new to dbi and quite new to perl. Please point me to my error

squark
Reply With Quote
  #2 (permalink)  
Old 09-25-05, 08:25
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
...Where is @column defined?

...Note that $tabdef ends with "DOUBLE,)" which will likely offend your database.
Reply With Quote
  #3 (permalink)  
Old 09-26-05, 12:27
squark squark is offline
Registered User
 
Join Date: Sep 2005
Posts: 2
appendix

the filling of the @column field is a bit complex. the script searches for column definitions in a data file and pushes them into @column, but its equivalent to

@column=( 'found_at', 'extent_offs', 'di_inostamp', 'di_fileset', [...] );

the last comma is choped off by $tabdef =~ s/,$//; so thats not the problem.

btw. here are my version infos:
debian testing
perl v5.8.7
mysql-server 5.0.11beta
libdbi-pelr1.48-1

squark
Reply With Quote
  #4 (permalink)  
Old 09-27-05, 18:14
senza_nome senza_nome is offline
Registered User
 
Join Date: Jun 2004
Location: Nowhere Near You
Posts: 89
... my bad, I'll have a look again.
Reply With Quote
  #5 (permalink)  
Old 10-12-05, 07:17
felixg felixg is offline
Registered User
 
Join Date: Apr 2005
Location: Lier, Belgium
Posts: 122
Quote:
Originally Posted by senza_nome
Code:
$tabdef = "CREATE TABLE inode(".$tabdef." )";
$dbh->do("DROP TABLE inode");
$sth = $dbh->prepare($tabdef) or die "Can't prepare $tabdef: $dbh->errstrn";
$sth->execute or die "Can't execute: $dbh->errstrn";
$sth->finish;
Why don't you use
Code:
$dbh->do($tabdef) or die ...
You $sth->execute line should read:
Code:
$sth->execute or die "Can't execute: " . $dbh->errstr;
if you want to see the error message.

--
felix
Reply With Quote
  #6 (permalink)  
Old 10-12-05, 10:31
true novice true novice is offline
Registered User
 
Join Date: May 2005
Posts: 20
Felixg:

Just curious as to how you managed to get squark's code attributed to senza_nome?
Reply With Quote
  #7 (permalink)  
Old 10-12-05, 10:35
felixg felixg is offline
Registered User
 
Join Date: Apr 2005
Location: Lier, Belgium
Posts: 122
Quote:
Originally Posted by true novice
Felixg:
Just curious as to how you managed to get squark's code attributed to senza_nome?
Oops... apologies. My mistake.
I should not manually cut and paste and fool around with the tags.

--
felix
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On