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
 All Forums
 Origin Forum for Programming
 Forum for Python
 Does 'Embedded Python' support SQL database?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
rkpara10 Posted - 12/31/2020 : 10:17:58 AM
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
5   L A T E S T    R E P L I E S    (Newest First)
rkpara10 Posted - 01/04/2021 : 12:45:19 PM
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
Castiel Posted - 12/31/2020 : 5:56:00 PM
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
------------------------------------------
cpyang Posted - 12/31/2020 : 2:45:15 PM
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
rkpara10 Posted - 12/31/2020 : 1:38:53 PM
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
Castiel Posted - 12/31/2020 : 10:37:31 AM
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
------------------------------------------

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000