Python Sample SQLite

From truxwiki.com
Revision as of 08:38, 19 February 2024 by Sam (talk | contribs)
Jump to navigation Jump to search

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())