Reading a MySQL dump file in C/C++?

This is a discussion on Reading a MySQL dump file in C/C++? within the MySQL Database forums, part of the Database Forums category; Hi all I have an textual dump of a database that I believe was created from MySQL. The format is ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-21-2008
jkn
 
Posts: n/a
Default Reading a MySQL dump file in C/C++?

Hi all

I have an textual dump of a database that I believe was created
from MySQL. The format is something like:

table = wire
size = 16
id_min = 39
id_max = 273
action;id;name;number;begin;height;weight;board;fi nal;turret
A;39;113;113;50;1;;;;76
A;40;114;114;50;1;;;;88
A;41;118;118;50;1;;;;73
A;42;120;120;50;1;;;;82

(There are a series of these tables, and I've changed the names).

I have a need to read the database using C or C++ into a set of
structures on which I can then perform a limited number of lookups. I
can't use any MySQL libraries.

I realise this is going the long way about things in some ways, and I
can at a pinch simply scan this file using 'Raw C' and build up my own
structures. But I imagine that this sort of thing has been done before
and wonder if there might be a framework out there that I could use to
assist me with this. (Answers of 'install MySQL' or similar not
helpful, sorry ;-o ).

Thanks for any suggestions.

Regards
Jon N
Reply With Quote
  #2 (permalink)  
Old 04-21-2008
Peter H. Coffin
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?

On Mon, 21 Apr 2008 05:14:29 -0700 (PDT), jkn wrote:
> Hi all
>
> I have an textual dump of a database that I believe was created
> from MySQL. The format is something like:
>
> table = wire
> size = 16
> id_min = 39
> id_max = 273
> action;id;name;number;begin;height;weight;board;fi nal;turret
> A;39;113;113;50;1;;;;76
> A;40;114;114;50;1;;;;88
> A;41;118;118;50;1;;;;73
> A;42;120;120;50;1;;;;82
>
> (There are a series of these tables, and I've changed the names).
>
> I have a need to read the database using C or C++ into a set of
> structures on which I can then perform a limited number of lookups. I
> can't use any MySQL libraries.


Not a mysqldump I've ever seen.

> I realise this is going the long way about things in some ways, and I
> can at a pinch simply scan this file using 'Raw C' and build up my own
> structures. But I imagine that this sort of thing has been done before
> and wonder if there might be a framework out there that I could use to
> assist me with this. (Answers of 'install MySQL' or similar not
> helpful, sorry ;-o ).


First step is to find out what exactly it is.

--
The greatest dangers to liberty lurk in insidious encroachment by men of
zeal, well-meaning but without understanding. -Justice Louis D. Brandeis
Reply With Quote
  #3 (permalink)  
Old 04-21-2008
jkn
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?

Hi Peter
>
> Not a mysqldump I've ever seen.


Fair enough - this is entirely possible. It's generated by a third
party to which I only have limited access.

[...]

> First step is to find out what exactly it is.


No, not really, because I already know that I can parse it. I've
written a small python program to do that. So regardless of how it's
generated (and I may not be able to find out any more than I know
already), I have to read it as-is.

Thanks anyway
J^n
Reply With Quote
  #4 (permalink)  
Old 04-21-2008
Kees Nuyt
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?

On Mon, 21 Apr 2008 05:14:29 -0700 (PDT), jkn
<jkn_gg@nicorp.f9.co.uk> wrote:

>Hi all
>
> I have an textual dump of a database that I believe was created
>from MySQL. The format is something like:
>
>1>table = wire
>2>size = 16
>3>id_min = 39
>4>id_max = 273
>5>action;id;name;number;begin;height;weight;board ;final;turret
>6>A;39;113;113;50;1;;;;76
>7>A;40;114;114;50;1;;;;88
>8>A;41;118;118;50;1;;;;73
>9>A;42;120;120;50;1;;;;82
>
>(There are a series of these tables, and I've changed the names).
>
>I have a need to read the database using C or C++ into a set of
>structures on which I can then perform a limited number of lookups. I
>can't use any MySQL libraries.


Hm, then why ask here?

>I realise this is going the long way about things in some ways, and I
>can at a pinch simply scan this file using 'Raw C' and build up my own
>structures. But I imagine that this sort of thing has been done before
>and wonder if there might be a framework out there that I could use to
>assist me with this. (Answers of 'install MySQL' or similar not
>helpful, sorry ;-o ).


I don't know of a framework that does this for you.
If I were you I would write an awk script and pipe the
resulting statements into sqlite (yes, I'm promiscuous,
there's more in life than MySQL).
awk should be part of the toolbox of every software
engineer. SQLite doesn't have to be "installed", it's
just one executable which can be easily used in shell
scripts, and one library which you can link statically
or dynamically in your C/C++ program.

http://www.sqlite.org/

I numbered the lines in your sample. Line 1 and 5 can
be transformed into

CREATE TABLE wire (
action,
id,
name,
:
:
);

Line 6 and above can easily be transformed into
statements like:
INSERT INTO wire
(action,id,name,....)
VALUES
("A",39,113,.....);

>Thanks for any suggestions.
> Regards
> Jon N


HTH
--
( Kees
)
c[_] Spirtle, n.: The fine stream from a grapefruit that always lands right in your eye.
(Sniglets, "Rich Hall & Friends") (#521)
Reply With Quote
  #5 (permalink)  
Old 04-22-2008
ThanksButNo
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?

On Apr 21, 1:22 pm, jkn <jkn...@nicorp.f9.co.uk> wrote:
> Hi Peter
>
>
>
> > Not a mysqldump I've ever seen.

>
> Fair enough - this is entirely possible. It's generated by a third
> party to which I only have limited access.
>
> [...]
>
> > First step is to find out what exactly it is.

>
> No, not really, because I already know that I can parse it. I've
> written a small python program to do that. So regardless of how it's
> generated (and I may not be able to find out any more than I know
> already), I have to read it as-is.
>



Sounds to me like you already have your solution. Use the Python
program to parse it, and do with it what you will.

If you need help on parsing in C/C++ because it *must* be in C/C++,
you probably should ask in one of the C/C++ newsgroups.
Reply With Quote
  #6 (permalink)  
Old 04-23-2008
jkn
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?

Hi Kees

> >I have a need to read the database using C or C++ into a set of
> >structures on which I can then perform a limited number of lookups. I
> >can't use any MySQL libraries.

>
> Hm, then why ask here?


Becauue I assumed that knowledge of MySQL may extend to 'knowledge of
things allied to MySQL'. At least, that's how it works in my domains
of knowledge ;-)

[...]
> I don't know of a framework that does this for you.
> If I were you I would write an awk script and pipe the
> resulting statements into sqlite (yes, I'm promiscuous,
> there's more in life than MySQL).


Err, exactly - see above! ;-P

Thanks - I know awk (a little), although I use Python (which also uses
sqlite) more myself.

[useful example snipped]

As it goes I've been able to write my own C++ to parse it. Hurrah! but
thanks anyway.

Cheers
J^n
Reply With Quote
  #7 (permalink)  
Old 04-23-2008
jkn
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?

Hi Kees

PS: I realised just after I'd posted that your suggestion about
embedding sqlite might be a good fit for my application, and one that
I'd not thought about. So regardless of how I parse this data this
might be something I'll try. Thanks for the idea.

Regards
J^n
Reply With Quote
  #8 (permalink)  
Old 04-23-2008
Kees Nuyt
 
Posts: n/a
Default Re: Reading a MySQL dump file in C/C++?


Hi J^n,

On Wed, 23 Apr 2008 01:52:39 -0700 (PDT), jkn
<jkn_gg@nicorp.f9.co.uk> wrote:

>Hi Kees
>
> PS: I realised just after I'd posted that your suggestion about
>embedding sqlite might be a good fit for my application, and one that
>I'd not thought about. So regardless of how I parse this data this
>might be something I'll try. Thanks for the idea.
>
> Regards
> J^n


You're welcome.
It's so nice to inspire people ;)
--
( Kees
)
c[_] Even if you have no other choices, remind yourself
that you can choose your attitude. (Henry Reed) (#297)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:23 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0