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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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) |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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) |