The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 Does 'Embedded Python' support SQL database?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rkpara10

United Kingdom
7 Posts

Posted - 12/31/2020 :  10:17:58 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,

I managed to install a python package called 'apsw-wheels' on Embedded Python using the 'Connectivity > Python Packages...' option in OriginPro. The 'apsw-wheels or apsw' is a Python wrapper for the SQLite embedded relational database engine. Then, I created the following script in Jupyter notebook.
--------------------------------------------------------------------
import apsw

### Opening/creating database

con=apsw.Connection("db_file")
cursor=con.cursor()
--------------------------------------------------------------------
The above script worked fine in Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error.

--------------------------------------------------------------------
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "D:\kaibasheer\Documents\OriginLab\User Files\apsw.py", line 5, in <module>
con=apsw.Connection("db_file")
AttributeError: module 'apsw' has no attribute 'Connection'
--------------------------------------------------------------------

Before I spend time to investigate the above issue, I would like to know, the current version of Embedded Python in OriginPro supports SQL database?

Thanks,
Raees

Origin Ver. and Service Release (Select Help-->About Origin): 2021
Operating System: Windows 10 HOME

Edited by - rkpara10 on 12/31/2020 1:50:57 PM

Castiel

343 Posts

Posted - 12/31/2020 :  10:37:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by rkpara10

Hello,

I managed to install a python package called 'apsw-wheels' on Embedded Python using the 'Connectivity > Python Packages...' option in OriginPro. The 'apsw-wheels or apsw' is a Python wrapper for the SQLite embedded relational database engine. Then, I created the following script in Jupyter notebook.
--------------------------------------------------------------------
import apsw

### Opening/creating database

con=apsw.Connection("db_file")
cursor=con.cursor()
--------------------------------------------------------------------
The above script worked fine in Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error.

--------------------------------------------------------------------
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "D:\kaibasheer\Documents\OriginLab\User Files\apsw.py", line 5, in <module>
con=apsw.Connection("db_file")
AttributeError: module 'apsw' has no attribute 'Connection'
--------------------------------------------------------------------

Before I spend time to investigate the above issue, I would like to know, the current version of Embedded Python in OriginPro supports SQL database?

Thanks,
Raees

Origin Ver. and Service Release (Select Help-->About Origin): 2021
Operating System: Windows 10 HOME



Rename your file. Do not name it as 'apsw'.


------------------------------------------
       Be The Change
             You Want To See
                   In The World
------------------------------------------
Go to Top of Page

rkpara10

United Kingdom
7 Posts

Posted - 12/31/2020 :  1:38:53 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Castiel,

Thanks for your suggestion. But, it's not working for me.

For simplifying my above question, I have recreated the above experiment using 'sqlite3' python package and the code is provided below.

--------------------------------------------------------------------
import sqlite3
### Opening/creating database
con = sqlite3.connect('db_file')
cursor=con.cursor()
--------------------------------------------------------------------
Again, the above script worked fine using Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error.
--------------------------------------------------------------------
#Error
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "D:\kaibasheer\Documents\OriginLab\User Files\TestPackages.py", line 3, in <module>
con = sqlite3.connect('db_file')
sqlite3.OperationalError: unable to open database file
--------------------------------------------------------------------

I am wondering, do you know the Embedded Python in OriginPro support SQL database?

Any suggestion from Originlab Technical Support would also be appreciated.

Regards,
Raees
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/31/2020 :  2:45:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I don't see error. Here is what I did

1. download sample SQLite from
https://www.sqlitetutorial.net/sqlite-sample-database/

2. place chinook.db to UFF, as that is where my py file will be

3. open Untitled.py from Connectiviy menu and put the code


import sqlite3
con = sqlite3.connect('chinook.db')
print(con)
cursor=con.cursor()
print(cursor)


I got
<sqlite3.Connection object at 0x000001D502B4FE40>
<sqlite3.Cursor object at 0x000001D502C5AB20>


sqlite3 was included into Python so there is no need to install it. Maybe you can remove apsw that you installed? Maybe that messed things up.


CP
Go to Top of Page

Castiel

343 Posts

Posted - 12/31/2020 :  5:56:00 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by rkpara10

Hi Castiel,

Thanks for your suggestion. But, it's not working for me.

For simplifying my above question, I have recreated the above experiment using 'sqlite3' python package and the code is provided below.

--------------------------------------------------------------------
import sqlite3
### Opening/creating database
con = sqlite3.connect('db_file')
cursor=con.cursor()
--------------------------------------------------------------------
Again, the above script worked fine using Jupyter Notebook. However, when I tested the above script using the Code Builder (Embedded Python) option in OriginPro, I got the following error.
--------------------------------------------------------------------
#Error
Traceback (most recent call last):
File "<string>", line 6, in <module>
File "D:\kaibasheer\Documents\OriginLab\User Files\TestPackages.py", line 3, in <module>
con = sqlite3.connect('db_file')
sqlite3.OperationalError: unable to open database file
--------------------------------------------------------------------

I am wondering, do you know the Embedded Python in OriginPro support SQL database?

Any suggestion from Originlab Technical Support would also be appreciated.

Regards,
Raees



con = sqlite3.connect('db_file')

Where is the db_file located? Is 'db_file' the full path?


------------------------------------------
       Be The Change
             You Want To See
                   In The World
------------------------------------------
Go to Top of Page

rkpara10

United Kingdom
7 Posts

Posted - 01/04/2021 :  12:45:19 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Cpyang and Castiel,

Thank you both for your suggestions, and the modified code below is working.

I did the following;
1. Uninstalled 'apsw' package
2. Provided an explicit path to .db file

Code:
import sqlite3
con = sqlite3.connect('D:/kaibas/Documents/OriginLab/User Files/chinook.db')
print(con)
cursor=con.cursor()
print(cursor)

Output:
<sqlite3.Connection object at 0x000001AA017D15D0>
<sqlite3.Cursor object at 0x000001AA0194B0A0>


Thanks,
Raees
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000