Click here to Skip to main content
15,867,870 members
Articles / Desktop Programming / MFC
Article

Database info tool

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
26 Oct 2000 80.9K   2K   39   5
Explore the structure of tables (and views)
  • Download source files - 19 Kb
  • Sample Image - DBInfo.gif

    What is this?

    This useful tool solves me a big problem: the ability to see what's the structure of a table in a database. Using this software you can read structure of tables, views and system tables. You can also list that structure into a .TXT file or print directly for a convenient use.

    How to use

    Since the access to the database is done via ODBC, you can read every database having only the right ODBC drivers.

    Normally each database you can access, has it's own DSN (data source name) identified by an unique name: clicking on button Select DB you can see the list of defined DSN, select the one you want inspect and read all tables' structure.

    If you enable Views and System Tables, you can see all views and system tables. Some databases (as ACCESS 97) don't allow you to read system tables. Select the table (or view) in the combo and see what's inside. You don't have the specific DSN for your database? Don't worry: select, from the DSN list, the DSN of the database engine it will automatically ask what database (often a file) to handle, and DBInfo will do the rest.

    Known Bugs

    I know that the code is NOT a valid example for beginner programmers... as you can see, minimal exception handling, no UNICODE support, and so on. But it's intended for programmers only; a crash isn't a problem in that case.

    You can find a bug that doesn't represent a real problem: if the table has a space (or minus sign) in its name, I enclose the table name between two brackets; some database engines doesn't like this. In that case a message will inform you about this problem.

    This is the code I use:

    // add [ & ] if name contains spaces or others chars
    if( sBuffer.Find(' ') != -1 ||
        sBuffer.Find('-') != -1 ) {
        sSQL  = "SELECT * FROM [";
        sSQL += sBuffer;
        sSQL += "]";
    } else {
        sSQL  = "SELECT * FROM ";
        sSQL += sBuffer;
    }

    where sBuffer contains the name of the table (or view).

    Special Thanks

    This tool was wrote after I did learn valid programming technique reading great code from George Poulose [Interactive SQL Tool (using ODBC)], Chris Maunder [Printing without the Document/View framework] and Richard Stringer [Printing Class Library] jobs.
    Without their articles I would be unable to create this tool. Thanks again guys!

    That's all folks!

    If you have some minutes to waste, visit my homepage.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Software Developer (Senior) SOFTHOR
    Italy Italy
    Too lazy to write something about me...

    Comments and Discussions

     
    QuestionWhy... Pin
    LowFly10-Jan-12 20:19
    LowFly10-Jan-12 20:19 
    Generalsql error Pin
    rasha7615-Sep-04 21:36
    rasha7615-Sep-04 21:36 
    GeneralSQLBrowseConnection Pin
    Simone Giannecchini16-Dec-01 1:57
    Simone Giannecchini16-Dec-01 1:57 
    QuestionExcel tables? Pin
    Ammar17-Apr-01 2:16
    Ammar17-Apr-01 2:16 
    AnswerRe: Excel tables? Pin
    Massimo Colurcio17-Apr-01 7:54
    professionalMassimo Colurcio17-Apr-01 7:54 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.