View Single Post

  #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