I need a struct or something similar to it but what and how?

Dear C++ Experts
what I want to archive is to get something like this:

echo databaseTable // list of all tables from this database


echo databaseTable.tableName // list of all fields from this database table


echo databaseTable.tableName.fieldName // name of that specific field

here is the basic thing that I wish to make it if it will be possible. is an array in array?? like in php? any other data type??


eg.
I have two database:db1 and db2.

db1 with following tables: table1 and table2 and table3
db2 with following tables: table1a and table2a and table3a

Table1 fields: id, name, comp
Table2 fields: id, book, author
Table3 fields: id, field1, field2

Table1a fields: id, fieldName, fieldName1
Table2a fields: id, fieldName2, fieldName4
Table3a fields: id, fieldName, field2

so

echo databaseTable // will output db1, db2


so

echo databaseTable['db1']
or
echo databaseTable.db1
// will output table1, table2, table3

echo databaseTable['db1']['table2']
or
echo databaseTable.db1.table2
will output: id, book, author

and so on..


Thanks for your help..
Last edited on
C++ is a compiled language. The usage that you propose is more typical for interpreted languages, or (with your example) for a database client.

I don't say that it is impossible, but it does need relatively many bits.
may i know what bits to use? to make it a class? or a struct? or array?? witch is better?
Classes and structs are practically the same thing. Their only difference is the default visibility of their members.

"Array" means usually a block of memory that contain multiple objects. There are other "containers" too.

Your "databaseTable" is an object that contains a list of "database" objects (and possibly other data). Each database object has a name and a list of table objects.
Each table obviously has a name, and a list of records and a name for each field of record. Each record has fields.
and so on ...

Then, separately, there is a parser that reads user input and may call methods of objects (assuming that the input can be interpreted).
you are right. I'm using Qt and I need to create this type of class or structure for using as constants as I do not know what those values will be so I can not guess the db name or the table name.. but i need a class that can generate it and this is what i need. to retrieve the info as you just said.

"Your "databaseTable" is an object that contains a list of "database" objects (and possibly other data). Each database object has a name and a list of table objects.
Each table obviously has a name, and a list of records and a name for each field of record. Each record has fields.
and so on ..."

So.. I will need a class and make them objects?? can you give me a clue?
so the output of db.name will be a string or at QStringList (in Qt)
where db.getName("mainDb") will output >> myMainDB.db
I do not know what those values will be so I can not guess the db name or the table name

In other words, the data must be read from some source and stored in some data structure.

What is the source and how the data will be used?

Qt has Model-View-based classes for tabular data and database-client classes.
the data will be stored into a sqlite database and I will read it from there. what I will need is like an template for this..
1
2
MyDbClass myDb;
    myDb.getDbNames();



but how can I do it to work like this…

db("main").table

or

db("main").table("settings").fildsName

or

db("main").table("settings").fildsName("id")

can you help me too do such thing? how Qt is doing with QFile..
file.open() or like tableView.model.data(); how those different classes can be linked together? and to communicate…
Qt has a SQL module; classes for database operations. It can use sqlite.

http://qt-project.org/doc/qt-5/qtsql-index.html

They have example programs too: http://qt-project.org/doc/qt-5/qtsql-sqlbrowser-example.html
Topic archived. No new replies allowed.