Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8103937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:41:32+00:00 2026-06-05T23:41:32+00:00

I am using pyodbc to connect to various odbc compliant databases. Suppose a MySql

  • 0

I am using pyodbc to connect to various odbc compliant databases.

Suppose a MySql database has name, age, nationality in it. Now my requirement is that i have to produce a dictionary containing the records in it as for example:

{'Name' : 'a', 'Age' : '20'} 

if the query specified in the execute() method of pyodbc object.

What i did to get the colums headers i.e “Name”, “Age” is that i created a new table out of the select query and then used

select column_name from information_schema.columns where table_name=xxx

to get the column headers. I dont know if the queries ‘create table‘, ‘drop table‘ and ‘select column name ….’ command are all same for the odbc compliant databases. I checked for PostgreSql and MySql, the work fine, but if they are different, then i need to change my implementation and will be like:

if mysql:
    execute(this)
if posegresql:
    execute(this)
if ibmdb2:
    execute(this)

if the queries i mentioned above are same for all databases, then there is no problem, but if they are different, what can be the easy and efficient solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:41:33+00:00Added an answer on June 5, 2026 at 11:41 pm

    There is many problems in one question.

    At first there is DB-API which standardize some things and one of them is description of columns you got with SELECT. You should not use information_schema for such things. What will you show if you use columns from other tables, or just show COUNT(*) ? This is how to use description to obtain column names (tried with pyodbc and Northwind MS Access database):

    rs = c.execute("SELECT * FROM Categories")
    cols = [d[0] for d in rs.description]
    print(cols)
    for rs in c.fetchall():
        print(rs)
    

    As for SQL then no, every database has its own dialect. Some of it is common, but there are many differences. For example datetime strings can be quite different.

    Of course you can use database via DAL: https://en.wikipedia.org/wiki/Database_abstraction_layer , but I used only DAL from web2py. I think use of such existing DAL would be simplest think if you want to build something bigger and database independent. ODBC and similar standards like JDBC are only way to connect to database, do some queries or execute other statements, check metadata (column names etc), but they do not hide SQL dialect differences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to query ODBC compliant databases using pyodbc in ubuntu . For
Im trying to use Spyder with pyodbc to connect mysql using a PyQT4 gui
I am using pyodbc to manage my database connections. I am attempting to connect
I am currently selecting a large list of rows from a database using pyodbc.
I'm using pyodbc to query to an SQL Server database import datetime import pyodbc
Periodically when using pyodbc to create a connection to an oracle database, it kills
I'm using pyodbc to data-mine a big database in a .mbd (access) file. I
I'm using pyodbc to query a SQL Server 2008 database table with columns of
I have a Python script that writes to a MySQL database using mysql-python .
Using PHP, I can convert MySQL data or static table data to csv, Excel,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.