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 8344125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:16:02+00:00 2026-06-09T06:16:02+00:00

this is somewhat related to my earlier query.. Reading A Big File With Python

  • 0

this is somewhat related to my earlier query..

Reading A Big File With Python

The problem was with runtime, so i was suggested to use sqlite3 database, and it reduced the time to millisecond, and I am very happy, now the only problem i have is, connecting to different database files in the same folder. All the database files have the same tables.

The code I am using, reads only the first one, and doesnt seem to check the other databases.

The output is when the teacher, enters students ID, it is supposed to return the related records if found in the database table.

my Code is something like this, But I am sure I am doing something wrong, pardon me if its a silly one, as using sqlite3 for the first time.

#other codes above not related to this part
databases = []
directory = "./Databases"
for filename in os.listdir(directory):
    flname = os.path.join(directory, filename)
    databases.append(flname)

for database in databases:
    conn = sqlite3.connect(database)
    conn.text_factory = str
    cur = conn.cursor()
    sqlqry = "SELECT * FROM tbl_1 WHERE std_ID='%s';" % (sudentID)
    try:
        c = cur.execute(sqlqry)
        data = c.fetchall()
        for i in data:
            print "[INFO] RECORD FOUND"
            print "[INFO] STUDENT ID: "+i[1]
            print "[INFO] STUDENT NAME: "+i[2]
            #and some other info
        conn.close()
    except sqlite3.Error as e:
        print "[INFO] "+e

Thanks For Any guides

  • 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-09T06:16:04+00:00Added an answer on June 9, 2026 at 6:16 am

    @Whiskey, sometimes it helps to try to break the problem down into a minimal example and see if that works or where it breaks. Since you are able to see the database names being printed as they are opened, my guess would be a problem with the query or possibly the data in the db even tho the records seem to be there. When you say it doesn’t find the record you’re looking for does it just print out nothing or does it print out the “[INFO]” line in your exception handler?

    I put together the following minimal example, and it seems to be working as far as my understanding of your problem goes. My only other piece of advice to add to everyone else’s would be to parametrize your query rather than using the raw input directly to make your app a little more secure. Hope it helps:

    import os, sqlite3
    
    
    """
    Create the test databases:
    
    sqlite3 Databases/test_db1.db
    
    sqlite> CREATE TABLE foo ( id INTEGER NOT NULL, name VARCHAR(100), PRIMARY KEY (id) );
    sqlite> 
    
    
    sqlite3 Databases/test_db2.db
    sqlite> CREATE TABLE foo ( id INTEGER NOT NULL, name VARCHAR(100), PRIMARY KEY (id) );
    sqlite> INSERT INTO foo VALUES (2, 'world');
    
    """
    
    
    databases = []
    student_id = 2
    
    directory = "./Databases"
    for filename in os.listdir(directory):
        flname = os.path.join(directory, filename)
        databases.append(flname)
    
    for database in databases:
    
        try:
    
            with sqlite3.connect(database) as conn:
    
                conn.text_factory = str
                cur = conn.cursor()
                sqlqry = "SELECT * FROM foo WHERE id=:1;"
                c = cur.execute(sqlqry, [student_id])
    
                for row in c.fetchall():
                    print "-- found: %s=%s" % (row[0], row[1])
    
        except sqlite3.Error, err:
            print "[INFO] %s" % err
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This query is somewhat related to this earlier one on sorting where, it was
This issue is somewhat related: Problem with Code Generated by XSD.EXE: Sequence of Elements
I found a couple of questions somewhat related to this: httpclient-request-set-attribute-question commons-httpclient-adding-query-string-parameters-to-get-post-request but I
This is somewhat related to the question posed in this question but I'm trying
Somewhat related to this question , but in the absence of any answer about
This question is related somewhat to the one i asked HERE . Now, i
This is not 100% programming related. But I think this is somewhat useful because
My question is somewhat related to this thread: How to avoid Initialization of web
This is somewhat related to another question I've asked but I figure why not
Two questions somewhat related to each other: In a find / findAll query, is

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.