Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
.exe prob
#1
import sqlite3

def writeTofile(data, filename):
    # Convert binary data to proper format and write it on Hard Disk
    with open(filename, 'wb') as file:
        file.write(data)
    #print("Stored blob data into: ", filename, "\n")

def readBlobData(empId):
    try:
        sqliteConnection = sqlite3.connect('SQLite_Python.db')
        cursor = sqliteConnection.cursor()
        print("Connected to SQLite")

        sql_fetch_blob_query = """SELECT * from new_employee where id = ?"""
        cursor.execute(sql_fetch_blob_query, (empId,))
        record = cursor.fetchall()
        for row in record:
            #print("Id = ", row[0], "Name = ", row[1])
            name  = row[1]
            photo = row[2]
            

            print("Storing employee image and resume on disk \n")
            photoPath = r"C:\AdwCleaner\\" + name + ".txt"
            
            writeTofile(photo, photoPath)
            

        cursor.close()

    except sqlite3.Error as error:
        print("Failed to read blob data from sqlite table", error)
    finally:
        if (sqliteConnection):
            sqliteConnection.close()
            print("sqlite connection is closed")

# 1.G  2. M

readBlobData(1)
The above code works well in the folder in which it was created. But when I transfer it to another folder for making and run it I get the following output:
Connected to SQLite
Failed to read blob data from sqlite table no such table: new_employee
sqlite connection is closed
Reply
#2
You're only ever looking for the database in the current directory. If it doesn't exist there, I assume it's being created and so of course doesn't have your schema (because there's nothing in the code to do that). Why don't you pass the path to where the database lives?
buran likes this post
Reply
#3
Please let me know how to pass the path in the code. I am unable to create an .exe with the help of pyinstaller. The created .exe does not give the reqired output.
Reply
#4
Also let me know how to find the path where the database lives. I am trying this for the first time.
Reply
#5
Pass it as an argument to your program too. Look at argv in the sys module to get access to the arguments passed on the command line. Then, you'll be able to pass it to the function in which you need it.

Surely you know where the file is?!
Reply
#6
Instead of passing arguments canit be ingrained in the code itself please tell me how?
Reply
#7
I guess I'm not really understanding what you want to do. I thought you wanted to be able to run the program from a different place to where the database ia stored. You then either need to hardcode the path to it (meaning you'd have to change the program if you moved it) or pass it in to the program somehow (command line argument, config file, environment variable, ...). Of course, your program could scan your file system(s) to try and discover where the file is, but that may be slow and do you really want to write code to do that anyway?
Reply
#8
My prob is that when I give this file to pyinstaller the .exe created in the dist folder cannot access the table. So I want to have the table path in the program so that it can be known to the .exe .
Reply
#9
So either hardcode the full path, or pass it in, as I said above.
Reply
#10
OK Thanks! GOD BLESS YOU!!!!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Newbie prob Snakecharmer 3 16,950 Jan-29-2019, 10:04 PM
Last Post: Snakecharmer

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020