Subject | RE: [firebird-support] Import data from flat files |
---|---|
Author | Oleg Lebedev |
Post date | 2003-09-29T18:21:35Z |
I was under the impression that plain INSERTs would be too slow for the
amount of data I need to import. That's why SQL Server has a BCP
utility, PostgreSQL has a COPY utility. Does FireBird have any similar
utility that would do a bulk copy for me?
Thanks.
Oleg
-----Original Message-----
From: Milan Babuskov [mailto:albis@...]
Sent: Monday, September 29, 2003 11:56 AM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Import data from flat files
Importance: Low
Oleg Lebedev wrote:
//---------------
ibase_connect('database', 'user', 'pass');
$sql = 'insert into your_table (column list,...) values (';
$fp = fopen('csv_file', 'r');
while ($line = fread($fp, 10000)
{
$data = explode(',', $line);
$values = '';
foreach ($data as $d) // quote the text
$values[] = "'" . $d . "'";
ibase_query($sql . implode(',', $values) . ')');
}
fclose($fp);
ibase_commit();
//---------------
Well, you need to add some error checking and stuff, but it can do the
job really nice.
--
Milan Babuskov
http://fbexport.sourceforge.net
To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
*************************************
This e-mail may contain privileged or confidential material intended for the named recipient only.
If you are not the named recipient, delete this message and all attachments.
Unauthorized reviewing, copying, printing, disclosing, or otherwise using information in this e-mail is prohibited.
We reserve the right to monitor e-mail sent through our network.
*************************************
amount of data I need to import. That's why SQL Server has a BCP
utility, PostgreSQL has a COPY utility. Does FireBird have any similar
utility that would do a bulk copy for me?
Thanks.
Oleg
-----Original Message-----
From: Milan Babuskov [mailto:albis@...]
Sent: Monday, September 29, 2003 11:56 AM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Import data from flat files
Importance: Low
Oleg Lebedev wrote:
> Sory, I fogot to mention that I need to be able to import files intoYou can write quick&dirty(TM) PHP script to do it. Something like this:
> the FireBird database running on Linux RedHat 8.0. I have 1 GB of data
> to import, so I need a pretty fast utility for that. The best would be
> a similar to GBAK utility that can import data from flat files into DB
> tables. Any ideas?
> Thanks.
//---------------
ibase_connect('database', 'user', 'pass');
$sql = 'insert into your_table (column list,...) values (';
$fp = fopen('csv_file', 'r');
while ($line = fread($fp, 10000)
{
$data = explode(',', $line);
$values = '';
foreach ($data as $d) // quote the text
$values[] = "'" . $d . "'";
ibase_query($sql . implode(',', $values) . ')');
}
fclose($fp);
ibase_commit();
//---------------
Well, you need to add some error checking and stuff, but it can do the
job really nice.
--
Milan Babuskov
http://fbexport.sourceforge.net
To unsubscribe from this group, send an email to:
firebird-support-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
*************************************
This e-mail may contain privileged or confidential material intended for the named recipient only.
If you are not the named recipient, delete this message and all attachments.
Unauthorized reviewing, copying, printing, disclosing, or otherwise using information in this e-mail is prohibited.
We reserve the right to monitor e-mail sent through our network.
*************************************