Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. [SQLite3] handling returned data from PRAGMA table_info("table_name") in C#?

[SQLite3] handling returned data from PRAGMA table_info("table_name") in C#?

Scheduled Pinned Locked Moved Database
databasesqlitecsharphtmldebugging
9 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bbranded
    wrote on last edited by
    #1

    Hello, I'm attempting to query a list of tables from an SQLite3 database and have come across the query PRAGMA table_info("table_name") in the SQLite docs. Here is my code:

    OdbcConnection DbConnection;
    OdbcDataReader DbReader;

    DbConnection = new OdbcConnection("DSN=" + odbcConnName);

    DbConnection.Open();

    OdbcCommand DbCommand = DbConnection.CreateCommand();
    //check to make sure column names are present
    DbCommand.CommandText = ("PRAGMA table_info(bandwidth_records)");
    DbReader = DbCommand.ExecuteReader();

                while (DbReader.Read())
                {
                    Trace.WriteLine(DbReader\["type"\].ToString());
                }
    

    DbReader.Close();
    DbConnection.Close();

    However, DbReader.Read() is not returning true. Very weird. Any ideas? Thanks, Matt

    L D 2 Replies Last reply
    0
    • B bbranded

      Hello, I'm attempting to query a list of tables from an SQLite3 database and have come across the query PRAGMA table_info("table_name") in the SQLite docs. Here is my code:

      OdbcConnection DbConnection;
      OdbcDataReader DbReader;

      DbConnection = new OdbcConnection("DSN=" + odbcConnName);

      DbConnection.Open();

      OdbcCommand DbCommand = DbConnection.CreateCommand();
      //check to make sure column names are present
      DbCommand.CommandText = ("PRAGMA table_info(bandwidth_records)");
      DbReader = DbCommand.ExecuteReader();

                  while (DbReader.Read())
                  {
                      Trace.WriteLine(DbReader\["type"\].ToString());
                  }
      

      DbReader.Close();
      DbConnection.Close();

      However, DbReader.Read() is not returning true. Very weird. Any ideas? Thanks, Matt

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #2

      I am not sure what was wrong with your case, but a test on my system returned the correct info. Are you sure you want to use the PRAGMA commands in your programs? Based on the documentation future versions of SQLite will not guarantee the backward compatability for these PRAGMA commands.

      D 1 Reply Last reply
      0
      • B bbranded

        Hello, I'm attempting to query a list of tables from an SQLite3 database and have come across the query PRAGMA table_info("table_name") in the SQLite docs. Here is my code:

        OdbcConnection DbConnection;
        OdbcDataReader DbReader;

        DbConnection = new OdbcConnection("DSN=" + odbcConnName);

        DbConnection.Open();

        OdbcCommand DbCommand = DbConnection.CreateCommand();
        //check to make sure column names are present
        DbCommand.CommandText = ("PRAGMA table_info(bandwidth_records)");
        DbReader = DbCommand.ExecuteReader();

                    while (DbReader.Read())
                    {
                        Trace.WriteLine(DbReader\["type"\].ToString());
                    }
        

        DbReader.Close();
        DbConnection.Close();

        However, DbReader.Read() is not returning true. Very weird. Any ideas? Thanks, Matt

        D Offline
        D Offline
        Dimitri Witkowski
        wrote on last edited by
        #3

        This will not work in SQLite via ODBC (if you use SQLite.Data.Dll everything will be ok) However, using ODBC you can get table fields too. Here's a sample:

        DbConnection.Open();
        DataTable dt = DbConnection.GetSchema("Columns");
        foreach (var col in dt.Columns) {
        Console.Write(col + "\t");
        }
        foreach (DataRow row in dt.Rows) {
        foreach (object field in row.ItemArray) {
        Console.Write(field + "\t");
        }
        Console.WriteLine();
        }

        See my article about Windows 7 Taskbar timer here on CodeProject

        B 1 Reply Last reply
        0
        • L loyal ginger

          I am not sure what was wrong with your case, but a test on my system returned the correct info. Are you sure you want to use the PRAGMA commands in your programs? Based on the documentation future versions of SQLite will not guarantee the backward compatability for these PRAGMA commands.

          D Offline
          D Offline
          Dimitri Witkowski
          wrote on last edited by
          #4

          Hm.. loyal ginger, which SQLite-ODBC driver have you used? I want it too

          See my article about Windows 7 Taskbar timer here on CodeProject

          1 Reply Last reply
          0
          • D Dimitri Witkowski

            This will not work in SQLite via ODBC (if you use SQLite.Data.Dll everything will be ok) However, using ODBC you can get table fields too. Here's a sample:

            DbConnection.Open();
            DataTable dt = DbConnection.GetSchema("Columns");
            foreach (var col in dt.Columns) {
            Console.Write(col + "\t");
            }
            foreach (DataRow row in dt.Rows) {
            foreach (object field in row.ItemArray) {
            Console.Write(field + "\t");
            }
            Console.WriteLine();
            }

            See my article about Windows 7 Taskbar timer here on CodeProject

            B Offline
            B Offline
            bbranded
            wrote on last edited by
            #5

            Thanks! I will look into the DataTable class more. Perfect.

            D 1 Reply Last reply
            0
            • B bbranded

              Thanks! I will look into the DataTable class more. Perfect.

              D Offline
              D Offline
              Dimitri Witkowski
              wrote on last edited by
              #6

              DataTable class itself isn't exactly what you need - it just contains the data. You should look at GetSchema method of DbConnection class. This method returns the metaschema of data for different databases.

              See my article about Windows 7 Taskbar timer here on CodeProject

              B 2 Replies Last reply
              0
              • D Dimitri Witkowski

                DataTable class itself isn't exactly what you need - it just contains the data. You should look at GetSchema method of DbConnection class. This method returns the metaschema of data for different databases.

                See my article about Windows 7 Taskbar timer here on CodeProject

                B Offline
                B Offline
                bbranded
                wrote on last edited by
                #7

                Thanks! DbConnection class

                1 Reply Last reply
                0
                • D Dimitri Witkowski

                  DataTable class itself isn't exactly what you need - it just contains the data. You should look at GetSchema method of DbConnection class. This method returns the metaschema of data for different databases.

                  See my article about Windows 7 Taskbar timer here on CodeProject

                  B Offline
                  B Offline
                  bbranded
                  wrote on last edited by
                  #8

                  Is there a given interface to the ODBC items:

                  TABLE_CAT
                  TABLE_SCHEM
                  TABLE_NAME
                  COLUMN_NAME
                  DATA_TYPE
                  TYPE_NAME
                  COLUMN_SIZE
                  BUFFER_LENGTH
                  DECIMAL_DIGITS
                  NUM_PREC_RADIX
                  NULLABLE
                  REMARKS
                  COLUMN_DEF
                  SQL_DATA_TYPE
                  SQL_DATETIME_SUB
                  CHAR_OCTET_LENGTH
                  ORDINAL_POSITION
                  IS_NULLABLE

                  to only parse certain "fields?" Thanks for your time, Matt

                  D 1 Reply Last reply
                  0
                  • B bbranded

                    Is there a given interface to the ODBC items:

                    TABLE_CAT
                    TABLE_SCHEM
                    TABLE_NAME
                    COLUMN_NAME
                    DATA_TYPE
                    TYPE_NAME
                    COLUMN_SIZE
                    BUFFER_LENGTH
                    DECIMAL_DIGITS
                    NUM_PREC_RADIX
                    NULLABLE
                    REMARKS
                    COLUMN_DEF
                    SQL_DATA_TYPE
                    SQL_DATETIME_SUB
                    CHAR_OCTET_LENGTH
                    ORDINAL_POSITION
                    IS_NULLABLE

                    to only parse certain "fields?" Thanks for your time, Matt

                    D Offline
                    D Offline
                    Dimitri Witkowski
                    wrote on last edited by
                    #9

                    What do you mean as interface to the ODBC items? I don't completely understand your question. Please be more concrete, maybe I'll be able to help you.

                    See my article about Windows 7 Taskbar timer here on CodeProject

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups