Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working with Text Files

Status
Not open for further replies.

minckle

Programmer
Mar 17, 2004
142
GB
Im creating a Delphi 5 App with a Mysql DB backend, that deals with Contacts Details.

The user would like to import contacts from a .txt file into the DB using delphi App.

Im ok with connecting to the DB and running insert queries

is it be possible to import the txt file data into an array or string list which can then be looped through to run the insert query

The txt file would be in the following format:

"John","Smith","01272333222"
"Matt","Jones","01221122353"
"Chris","James","01382733212"


 
You should look at the MySQL command

LOAD DATA

to import your data into your MySQL table. This is much more efficient than using a sequence of INSERT commands and it can take your unconverted txt file without the requirement to load it into a string list or an array.

Assuming you want to load data from a text file called CUSTOMERS.TXT into a table called mytable, the
command would be something like
Code:
LOAD DATA LOCAL INFILE 'CUSTOMERS.TXT' 
INTO TABLE mytable
FIELDS TERMINATED BY ','
FIELDS ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'


Andrew
Hampshire, UK
 
Hi thanks for that. ive started to read it, but would it be possible to run this command using delphi

I.e the user clicks a button in my Delphi App and the 'Load Data Local ' command is run
 
What happens when you try it?

Why do you think it will be different from any other MySQL command?

Andrew
Hampshire, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top