Difference between revisions of "Python Sample SQLite"
Jump to navigation
Jump to search
(Created page with "It is possible to access [https://sqlite.org/ SQLite] files in Truxton without first exporting them. =APSW= Truxton will automatically create a unique identifier for your fil...") |
|||
| Line 2: | Line 2: | ||
=APSW= | =APSW= | ||
| − | + | Since the [https://docs.python.org/3/library/sqlite3.html Python DB-API] only supports establishing a connection to a SQLite database by providing a file name, we have to create our own filesystem to read from the data in Truxton. | |
| − | + | But, DB-API doesn't support virtual filesystems. | |
| + | However, another SQLite library called [https://rogerbinns.github.io/apsw/ APSW] does. | ||
| + | Install it using pip: | ||
| + | <source lang="bat"> | ||
| + | pip install apsw | ||
| + | </source> | ||
| + | You can verify that it is working by running the following script: | ||
| + | <source lang="python"> | ||
| + | from __future__ import annotations | ||
| + | from typing import Optional, Iterator, Any | ||
| + | |||
| + | import os | ||
| + | import sys | ||
| + | import time | ||
| + | import apsw | ||
| + | import apsw.ext | ||
| + | import random | ||
| + | import re | ||
| + | from pathlib import Path | ||
| + | |||
| + | def main() -> None: | ||
| + | |||
| + | print(" Using APSW file", apsw.__file__) | ||
| + | print(" APSW version", apsw.apsw_version()) | ||
| + | print("SQLite header version", apsw.SQLITE_VERSION_NUMBER) | ||
| + | print(" SQLite lib version", apsw.sqlite_lib_version()) | ||
| + | print(" Using amalgamation", apsw.using_amalgamation) | ||
| + | |||
| + | return None | ||
| + | |||
| + | if __name__ == "__main__": | ||
| + | sys.exit(main()) | ||
| + | </source> | ||
| + | |||
| + | =Truxton= | ||
<source lang="python"> | <source lang="python"> | ||
import sys | import sys | ||
| Line 17: | Line 51: | ||
sys.exit(main()) | sys.exit(main()) | ||
</source> | </source> | ||
| − | |||
| − | |||
| − | |||
Revision as of 08:38, 19 February 2024
It is possible to access SQLite files in Truxton without first exporting them.
APSW
Since the Python DB-API only supports establishing a connection to a SQLite database by providing a file name, we have to create our own filesystem to read from the data in Truxton. But, DB-API doesn't support virtual filesystems. However, another SQLite library called APSW does. Install it using pip:
pip install apsw
You can verify that it is working by running the following script:
from __future__ import annotations
from typing import Optional, Iterator, Any
import os
import sys
import time
import apsw
import apsw.ext
import random
import re
from pathlib import Path
def main() -> None:
print(" Using APSW file", apsw.__file__)
print(" APSW version", apsw.apsw_version())
print("SQLite header version", apsw.SQLITE_VERSION_NUMBER)
print(" SQLite lib version", apsw.sqlite_lib_version())
print(" Using amalgamation", apsw.using_amalgamation)
return None
if __name__ == "__main__":
sys.exit(main())
Truxton
import sys
sys.path.append('C:/Program Files/Truxton/SDK')
import truxton
def main() -> None:
return None
if __name__ == "__main__":
sys.exit(main())