views:

156

answers:

4

I have a problem here. I have about 13K rows of data that I want to put into a mysql database. What I notice is that if the row is "short" the insert will happen but if it is long, it fails. I have been trying to figure this out all day and I'm about to give up.

Here is the table structure.

CREATE TABLE `concordance` (
  `term` text NOT NULL,
  `ref` text NOT NULL,
  `id` int(11) NOT NULL auto_increment,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Here is a row that will go in just fine.

"Abelmeholah"*"JDG 7:22 KI1 4:12 19:16"

Here is a large row that fails.

"A"*"GEN 6:16 30:11 EXO 4:2,26 12:45 28:34 30:2 38:26 39:26 LEV 20:27 21:14 25:11 NUM 28:21,29 29:10 DEU 2:21 8:8-9 9:2 11:12,27 22:30 23:2 26:5 28:50 JDG 9:54 13:6 KI2 11:5 CH2 23:4 PSA 22:30 37:16 68:5 74:5 91:7 92:1,6 97:3 101:4 107:34 112:5 PRO 1:5 6:12,17,19,33 9:13 10:1 11:1,13,16 12:2-4,8,10,14,16,23 13:1-2,5,17,22 14:5-6,16,25,30 15:1,4-5,12-13,18,20,23 16:9-11,28-29 17:2,4,8,10,17-18,22-23,25 18:2,6-7,16,19-20,24 19:5,9,13,19,24 20:8,26 21:14,22,28-29 22:1,3 24:5 25:11,18,26 26:3,28 27:3,12,15 28:3,17,20 29:5,11,19,23 30:30-31 ECC 3:2-8 6:2 7:1 10:2,14,19 SOL 1:13 4:12,15 ISA 8:12 21:2,8 27:2 42:3 60:22 62:12 65:3 66:6 JER 2:24 3:21 4:11 5:30 11:9,16 17:12 20:15 25:31,36 31:15,22 48:3 50:22,35-38 51:54 EZE 5:12 17:3 19:2 21:9 36:26 DAN 7:10 JOE 2:2-3 AMO 7:8 8:2 HAB 3:1 ZEP 1:16 MAL 1:6 MAT 5:14 7:18 11:7-9 12:20,35 13:57 16:4 21:28 MAR 6:4 12:1 LUK 2:24,32 6:45 7:24-26 8:5 10:30 13:6 14:16 15:11 19:12 20:9 JOH 1:42 3:27 9:11 13:34 16:16-19,21 19:36 ACT 3:22 7:37 10:2 11:5 CO1 7:15 GAL 5:9 TI1 3:2 TIT 3:10 HEB 8:2,13 JAM 1:8 REV 6:6"

Any help is greatly appreciated.


Here is what I am using to get the data into the db

LOAD DATA LOCAL INFILE '/data.txt' 
INTO TABLE concordance 
FIELDS TERMINATED BY '*'


I just tried loading the large dataset above and here is the error: mysql> LOAD DATA INFILE '/tmp/data.txt' INTO TABLE concordance FIELDS TERMINATED BY '*'; ERROR 1261 (01000): Row 1 doesn't contain data for all columns


HERE IS THE CODE THAT WORKS:

LOAD DATA INFILE '/tmp/f.txt'
INTO TABLE `concordance`
FIELDS TERMINATED BY '*'
ENCLOSED BY '"'
(`term` , `ref`);
+1  A: 

Your table creation query is wrong:

#1072 - Key column 'seq' doesn't exist in table

Other than that, provided your query is ".... PRIMARY KEY (id) .... ", I can insert both lines of data without any problem. Maybe you should post your code.


Edit:

Try the following query:

LOAD DATA INFILE '/data.txt' INTO TABLE `concordance` FIELDS TERMINATED BY '*'
    ENCLOSED BY '"' LINES TERMINATED BY '\r\n'(
    `term` , `ref` 
)
Anax
Thanks Anax. I changed it and it is still doing the same thing. The PK is not the problem. It is now id. I will make the changes above
Jim
I'll post it above
Jim
Anax, that worked! Is it the CR and newline that did it?
Jim
That or the fact that you tell MySQL you only insert two out of three rows with local data.
Anax
Well, I even supplied the id column value and it failed. It is really weird.
Jim
I got it.. I will post the final code above.
Jim
A: 

this command worked for me:

LOAD DATA LOCAL INFILE 'C:\xampp\tmp\php3BF.tmp' INTO TABLE concordance FIELDS TERMINATED BY '*' ENCLOSED BY '"' ESCAPED BY '\' LINES TERMINATED BY '\r\n'

maybe you should provide value for id column too? or there is other error on line 1 in your file...

kipelovets
Thanks kipelovets, I'm not sure if there is an error on the first line or not but I believe that I need the lines terminated by '\r\n'. I don't understand why I need this though. Isn't it enough to use the ENCLOSED BY?
Jim
i'm not sure, but... that just works)
kipelovets
A: 

You might also want to ass a star at the end of each line, in order to tell MySQL that you want to skip the id field...

"Abelmeholah"*"JDG 7:22 KI1 4:12 19:16"*

It is strange though the short line goes in whereas the long line cannot..

ercan
I could try that as well. Honestly, I've never seen anything like this before. It is really strange. I will try this and see if it works.
Jim
Ercan, I just tried your suggestion and it fails. :(
Jim
A: 

This worked fine for me on a windows system. Have you tried escaping the commas in your text?

rwigfall