Given an SQLite .sql database file.

Is there a tool that can automatically create C++ structures from its tables?

For example, an sqlite schema in this form:

    [ID] integer primary key , 
    [IDGROUP] integer, 
    [USERNAME] text, 
    [FLAGS] integer default 0, 
    [NAME] text, 
    [VIEW_PASS] text, 
    [TRADE_PASS] text, 
    [IDCURRENCY] integer, 
    [BALANCE] real, 
    [LEVERAGE] integer

to a C++ structure like:

struct ACCOUNT {
    int ID;
    int IDGROUP;
    std::string USERNAME;
    int FLAGS;
    std::string NAME;
    std::string VIEW_PASS;
    std::string TRADE_PASS;
    double BALANCE;
    int LEVERAGE;

It does not need to be on the schema, it could be directly from the db.

  • I have rewritten your question assuming that you mean an SQLite database file; just a *.sql file could be anything. Now you please edit your question and add OS, price,...
    – user416
    Jul 23 '15 at 19:32
  • I do not know such tool, but with some scripting language like, say Python, you can make such tool in two hours assuming you already have C++ wrappers for SQL types.
    – DejanLekic
    Jul 23 '15 at 19:56
  • @JanDoggen what if OP really meant an *.sql file containing CREATE TABLE etc. statements? I mean, your guess makes much more sense to me – but I'm afraid we can't be sure until OP confirms. Without that, we might need to close this as "unclear".
    – Izzy
    Jul 23 '15 at 23:05
  • 2
    Thanks for further clarification – but still some more needed: You ask for a "tool", and your tags say a.o. c++. So what is it you are looking for: a library to be used with C++ – or a stand-alone tool you can use directly? In the latter case: what OS must be supported?
    – Izzy
    Jul 24 '15 at 10:37
  • Of course, it is not straightforward, given that the datatypes don't exactly overlap ... dev.mysql.com/doc/refman/5.0/en/data-types.html Jul 24 '15 at 11:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.