473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Extracting data from dump file

TYR
I have a large dump file that originated in a MySQL db; I need to get
it into an SQLite file.

Various options are suggested around the web; none of them seem to
work (most failing to import the thing in the first place). So I
removed the assorted taggery from each end, leaving just a big text
file taking the following format:

('value', 'value', 'value, 'value'),
('value','value','value','value')...

I planned to find some way of splitting the thing at the commas
outside the bracketed groups, thus giving me a list of tuples; then I
could of course CREATE TABLE foo VALUES '1', '2, '3', '4' and then
iterate through the list INSERTing INTO.

Then my problems began; I tried using the python csv method, replacing
the string ),( with \t and then using \t as the delimiter. First
problem; there's a size limit coded into the module. No problem, use
csv.field_size_limit() to alter it. Problem; it doesn't actually parse
at all, just sends the whole thing as a string and the SQL INSERT
fails with a "not enough args" error.

Tried using string.split() and re.split(data, r'\t'); first gave the
same error, second failed with a "too many named groups" error. Tried
using ; as a delimiter and going back to csv; this fails to match
the ; for some reason. Any ideas?
Nov 23 '07 #1
1 3660
On Nov 24, 5:46 am, TYR <a.harrow...@gmail.comwrote:
I have a large dump file that originated in a MySQL db; I need to get
it into an SQLite file.

Various options are suggested around the web; none of them seem to
work (most failing to import the thing in the first place). So I
removed the assorted taggery from each end, leaving just a big text
file taking the following format:

('value', 'value', 'value, 'value'),
('value','value','value','value')...
Consider the possibility that individual data rows are separated by "),
\n(" or maybe "), \n(" or something else, not "),(".

What does
print repr(open("my_dump.txt", "rb").read(1000))
tell you? Are there any "\n" in there at all? BTW, what platform are
you running on?
>
I planned to find some way of splitting the thing at the commas
outside the bracketed groups, thus giving me a list of tuples; then I
could of course CREATE TABLE foo VALUES '1', '2, '3', '4' and then
CREATE TABLE foo VALUES '1', .... are you sure?

iterate through the list INSERTing INTO.

Then my problems began; I tried using the python csv method, replacing
the string ),( with \t and then using \t as the delimiter. First
problem; there's a size limit coded into the module. No problem, use
csv.field_size_limit() to alter it.
>>import csv
csv.field_size_limit()
131072
>>>
And do you really expect that any one of your data rows will take more
than 128KB in the dump file?? How large did you have to set the limit
to make it "work"???
Problem; it doesn't actually parse
at all,
Sounds like it did parse, with the result being one csv row containing
one very long field.
just sends the whole thing as a string and the SQL INSERT
fails with a "not enough args" error.

Tried using string.split() and re.split(data, r'\t'); first gave the
same error, second failed with a "too many named groups" error.
All of these are indications that you don't have the correct
delimiter.
Tried
using ; as a delimiter and going back to csv; this fails to match
the ; for some reason. Any ideas?
Examine your dump carefully. Are there any newlines other than at the
logical end of data rows (like e.g. it's folded at column 78)? If so,
you'll have to replace those by spaces or delete them. Work out
exactly what is separating data rows. Let's call it "sep". If you can
use file_contents.replace(sep, "\t"), then you can use
file_contents.split(sep) directly; there's no need for a two step
approach. If sep is variable, then use re.split.

Try this on a small subset of your dump file. Before you go anywhere
near the database, check the results of your split: did you get the
expected number of rows [currently you are getting 1 row], does each
row look OK? Unsubtle hint: the first row may start with "junk(" and
the last may end with ")junk" if you haven't already allowed for that.

Then try inserting into the database. Print a row number and row
contents before each insert (or wrap try/except around each insert) so
that you know which row any error relates to.

If you still have a problem, ask again, but do show exactly what your
dump file looks like and what your code is -- my crystal ball needs a
long recharge after all of the above!

HTH,
John
Nov 23 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Droopy | last post by:
Hi, I am running an application on 74 PC (1 instance on each PC). This morning, 2 applications crashes. There were neither popup windows signaling it nor dump file created. I only find in the...
9
by: Shivam | last post by:
Hi All, I have a mysql dump file... something like. __________________________________________________ CREATE TABLE nation ( ip int(11) unsigned NOT NULL default '0', country char(2) NOT...
0
by: Sunil Basu | last post by:
Hi, I have a interesting thing to know and discuss with you. I am extracting data from an Excel file in a Delphi DbGrid through SQL. I want to create a criteria on a specific cell value of the...
0
by: runner7 | last post by:
I used file_get_contents() to read a pdf into a string and then tried to extract the encoded part between the "stream" and "endstream" words using the strpos() and substr() functions. (I could not...
0
by: sgsiaokia | last post by:
I need help in extracting data from another source file using VBA. I have problems copying the extracted data and format into the required data format. And also, how do i delete the row that is not...
1
by: avinash jain | last post by:
I got a segmentation fault.. I came to know that the problem could be easliy solved be the core dump files. could any tell how to create a core dump file and how to read a core dump file. I am...
1
by: JSagar | last post by:
Hello Expert ! I am new to python , i had done 'C' Code , which extracted file data , But i don't want to give my exe On remote side. Following thing is it Possible using python? -...
1
by: davidson1 | last post by:
Hai friends, In our college we have oracle database , i need the old records for testing my project , and the old records are in dump file. Now i need to tranfer the data from oracle dump file...
4
by: poolboi | last post by:
hi guys i've having some problem extracting data from a text file example if i got a text file with infos like: Date 2008-05-01 Time 22-10 Date 2008-05-01 Time 21-00 Date 2008-05-02 Time...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.