Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #2 on: Jul 08, 2006, 10:42:23 am »
The data is |-seperated so it looks something like this:
234234|AAAA|abcd|2006-03-04
The SQL looks like this:
Code:
{ TABLE "itis".change_comments row size = 263 number of columns = 4 index size = 30 } { unload file name = chang00100.unl number of rows = 0 }
create table "itis".change_comments ( change_track_id integer not null , chg_cmt_id serial not null , change_detail varchar(250,1) not null , update_date date not null ); revoke all on "itis".change_comments from "public";
and then after all the table definitions there's some key and constraints defenitions:
Code:
create unique index "itis".change_comments_ky on "itis".change_comments (change_track_id,chg_cmt_id) using btree ; alter table "itis".change_comments add constraint primary key (change_track_id,chg_cmt_id) constraint "itis".u111_1 ;
and
Code:
update statistics medium for table comments ( comment_detail, comment_id, comment_time_stamp, commentator, update_date) resolution 2.50000 0.95000 ;
« Last Edit: Jul 08, 2006, 10:56:05 am by Mind_nl »
Global Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6690
34708 credits Members referred : 374
It's time to use PHP5!
« Reply #5 on: Jul 08, 2006, 12:06:09 pm »
first you have to create a table (is easy, read the beginners tutorials) and then locate this option "Insert data from a textfile into table" (tab sql) that's all
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #6 on: Jul 08, 2006, 12:55:16 pm »
yes, I know how to create a table in phpMyAdmin. The problem is that the exported SQL doesn't work. The posted data is just a sample, there are a lot of tables in the database with a lot of constraints and indexes. It would be nice if there would be a tool to translate the Informix SQL to MySQL SQL. I've see some commercial tools for this, but I'm looking for the cheap way...
yes, I know how to create a table in phpMyAdmin. The problem is that the exported SQL doesn't work. The posted data is just a sample, there are a lot of tables in the database with a lot of constraints and indexes. It would be nice if there would be a tool to translate the Informix SQL to MySQL SQL. I've see some commercial tools for this, but I'm looking for the cheap way...
how many tables do you have 100 ? just create a few tables manually and if you want to translate all sql statements (update, insert, select...), be carefull you are running on thin ice...
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5660
45593 credits Members referred : 3
« Reply #12 on: Jul 12, 2006, 09:27:09 pm »
Why don't you do it manually?
For the example I see you will need something like :
Code:
<?php $records = explode("\n", $input); //$input = the data you have foreach ( $records as $l ) { $rec = explode('|', substr($l,0,-1)); //Do something with the $rec }
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #13 on: Jul 12, 2006, 10:01:06 pm »
yeah that sounds good! but: 1. how do I get the data in $input (do I load the whole file at once?) 2. I get the $rec = explode('|' but where do I find the 3 values after the explode (so what do I need to use on the INSERT? Thanks!
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 5660
45593 credits Members referred : 3
« Reply #14 on: Jul 12, 2006, 10:06:35 pm »
1. If the file ia too big, it would be better to use fgets, but you wont have any problem with files bigger than 500 mb.
2. After the explode, $rec[0] is the first value, $rec[1] is the second, etc. If you are asking wich field goes with each value, then this is not a problem as in mysql you can say INSERT INTO table (value1,value2,value3,.....)
Global Moderator
Internet Junkie
Gender:
Posts: 1807
9006 credits Members referred : 6
« Reply #18 on: Jul 13, 2006, 11:24:27 am »
I'm filling up the database, the first couple of file went oke, but I'm getting errors now. I think the error is because of commas in the field value. What would be the best way to fix this? The data looks like this:
I'm filling up the database, the first couple of file went oke, but I'm getting errors now. I think the error is because of commas in the field value. What would be the best way to fix this? The data looks like this:
123|aaa,2|bbb
The problem is not the comma. Do you use ' for every value that you insert?