Re: perl with mysql which takes a file as a input that contains the info to create the tables



Hi Prady,

In your example script you are feeding the execute command a set of strings,
so you know that it will except a string.

Since the creation of a table is not something that you need to prepare, all
you will need to do is shove the create table command in a single string
(optionally with line feeds) and hand that to the $dbh->execute() command.

Whatever command your string contains is then executed on your database so
assuming your create table command was syntactically correct SQL the table
will be created in your database.

Regards,

Rob

*ps, you do not need to prepare your command on the database, but since you
are executing the same SQL command several times with just different
variables preparing the command on the database and using placeholders will
make the whole thing go a bit faster (assuming your database can work with
place holders.*


On 10/30/07, prady <prady184u@xxxxxxxxx> wrote:

hi all

i am creating a perl script which takes the input from the file to
create tables, inserting values into the database. As you all know the
only procedure for taking input from a file (using perl script) into
MySQL database is through (?) place holders.
for example ,

$sth=$dbh->prepare
("INSERT INTO checkin (firstname, lastname, destination)
VALUES
(? , ? , ? )");

$rows=0;
open FILE, "passlist.txt" or die $!;
while (<FILE>) {
chomp;
($firstname, $lastname, $destination) = split(/:/);
$sth->execute($firstname, $lastname, $destination)
|| die "Couldn't insert record : $DBI::errstr";

$rows+=$sth->rows();
}

Where the passlist.txt hav the data in the format

Tim:Briggs:Glasgow
Simon:Cozens:Japan
Richard:Collins:Japan
Daniel:Maharry:Glasgow
Emma:Batch:Thailand

Now it is perfect that v can take input from a file...

P.S. : But i wanted to take INPUT that contains the info to create the
tables
Where
CREATE TABLE checkin (
id INTEGER AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(32) NOT NULL,
lastname VARCHAR(32) NOT NULL,
checkedin INTEGER,
numberofbags INTEGER,
destination VARCHAR(32) NOT NULL)

NOW I WANTED TO KNOW THE PROCEDURE FOR TAKING THE CODE AS INPUT FROM A
TEXT FILE & CREATE THE SPECIFIED TABLE

awaiting ur reply

Regards
prady


--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/





Relevant Pages

  • Re: Creation of DSN
    ... Build a text string from the input data. ... rather execute the string that was just built. ... script file has been processed. ... > I'm using directly a Command, ...
    (microsoft.public.vb.database.ado)
  • Re: perl with mysql which takes a file as a input that contains the info to create the tables
    ... in the above text format u can find two tables one is Details> & the other ... strings, so you know that it will except a string. ... all you will need to do is shove the create table command in a single string ... Whatever command your string contains is then executed on your database so ...
    (perl.beginners)
  • Re: SET IDENTITY_INSERT tablename ON problem
    ... Try to combine all statements into one string and then execute them in one ... A couple of my tables use identity columns. ... > The next command is to insert the data but I get an error that says I ...
    (microsoft.public.vb.database.ado)
  • Re: DB Space
    ... > "Hari Prasad" wrote: ... >> Can you execute the below command to ghet the actual database size. ...
    (microsoft.public.sqlserver.msde)
  • RE: Event ID 447
    ... Please made a backup for Exchange database first. ... Please run the eseutil /mh command to see if the mailbox store is clean ... Microsoft CSS Online Newsgroup Support ...
    (microsoft.public.windows.server.sbs)