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



hi Rob,

What exactly i wanted to do is..

to take a input from a file of format :

INPUT.txt :

Details> name , id INTEGER, area VARCHAR(32)
prady,2039,india
sandy,2398,india
sam,1234,aussie
Rob,2345,Eng
extraDetails>name1 VARCHAR(12), name2 VARCHAR(12)
prady,sandy
sandy,Rob
Rob,sam
sam,prady


in the above text format u can find two tables one is Details> & the other
is extraDetails>

so i wanted to take the line Details> for creating table , & the values
below it for inserting into the table. similarly the second shud be find out
(extraDetails) & those values shud be inserted in to its table

& one more script the other way round like by getting the (retrieving) the
data from the mysql database using some queries & creating a file in the
above specified INPUT.txt format.

could u please help me in this regard
thanx
Regards
Prady
On 10/30/07, Rob Coops <rcoops@xxxxxxxxx> wrote:

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/






--
wid luv
prady


Relevant Pages

  • Re: [PHP] Date/time format?
    ... Jason Pruim wrote: ... I am trying to figure out what format a string is in in a database. ... Below is an example of one of the lines in the database, What I'm really interested in is how it represents the "day". ... I have not been able to find ANY info about that format, other then other people using it in blogs. ...
    (php.general)
  • Re: year to date conversion
    ... the date in ISO-format, i.e. exactly in the format the OP requested. ... It is rare to need to be database independent. ... Sure, but again, there are moments, where a PreparedStatement ... The string is created by java.sql.Date, ...
    (comp.lang.java.programmer)
  • Re: [PhP - dB] About Formatting a Date Result
    ... In the MySQL database the field is set to date not timestamp as you ... foresight has stored a string date instead of a timestamp, ... and can format your date to that used, in the config files, for any user ...
    (php.general)
  • Re: Getting entries from an SQL database with datetime parameter
    ... format is what you want. ... funtion to convert date string into date time accordig to your needs. ... your database, you will run into troubles comparing date to string. ... > hard coded a query to populate the datagrid, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Manipulation of strings query
    ... I have received the data in an excel spreadsheet which contains the names in ... that I could enter it as 2 fields in a database and I'm certainly not doint ... The problem with the string input is that users will not be entering the ... > cintains names in the format LASTNAME, ...
    (microsoft.public.inetserver.asp.general)