SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL. The FairCom DB SQL Python interface provides support for this technology.
More details about SQLAlchemy are available at SQLAlchemy.org.
To get started with SQLAlchemy, see the following folder:
\drivers\python.sql.sqlalchemy
FairCom recommends that the tutorials for the Python APIs be run using Python version 3 - preferably version 3.4+. Accordingly, in the instructions below, we have made the following assumptions about how the user's machine is configured:
Windows: The PATH, etc. should be configured in such a way that invoking python at the command-line will run version 3 of Python and invoking pip at the command-line will run the instance of pip that is associated with that version of Python.
Linux: The system should be configured in such a way that invoking python3 at the command-line will run version 3 of Python and invoking pip3 at the command-line will run the instance of pip that is associated with that version of Python.
These assumptions are also made by the batch files (Windows) and make files (Linux) FairCom provides to run the tutorials and by the instructions bellow. If these assumptions are not correct, users are encouraged to reconfigure their machines to match the assumptions. Alternatively, you can modify the instructions that follow and the batch file and/or make file to match the machine's configuration.
Bit Depth: It is important that the bit depth of the Python version 3 you are using matches the bit depth of the FairCom product you are using.
This package contains the FairCom DB SQL dialect for SQLAlchemy. The dialect enables using FairCom DB SQL with SQLAlchemy, the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL. More details are available at SQLAlchemy.org.
Note: This driver was specifically developed and tested on SQLAlchemy 1.0.19 with both Python 2.7 and Python 3.5-3.9. It supports SQLAlchemy 1.0 and higher and Python 2.7 and Python 3.0 forward.
Installation
Reminder: setuptools and wheel are prerequisites before SQLAlchemy can be installed on Linux. If you do not have them installed, execute the following before installing SQLAlchemy:
pip install setuptools
pip install wheel
<faircom>\drivers\python.sql.sqlalchemy
Windows:
pip install sqlalchemy
python setup.py install
Linux:
pip3 install sqlalchemy
python3 setup.py install
If any steps have permission problems, use sudo to run that command.
If step 4 produces the following error, you will need to update your setuptools package:
setuptools_scm.version.SetuptoolsOutdatedWarning: your setuptools is too old (<12)
Un-install the old version of the Python setuptools package and install a later version, as follows:
After updating setuptools, try step 4 again.
To run the tutorial (after doing the installations mentioned above), use the batch file (Windows) or make file (Linux) in the <faircom>\drivers\python.sql.sqlalchemy\tutorials\cmdline folder, as follows:
cd tutorials\cmdline
Windows: BuildTutorials.bat
Linux: make build; make run
On Linux, the build command copies a library to the correct location and the run command runs the tutorial.
The tutorial should print the following:
<User(id='1', name='u1')>
[<Address(email='one')>, <Address(email='two')>]
Problem: "ImportError: No module named setuptools"
Solution: Install setuptools as described above.
Problem: "pyctree missing"
Solution: Be sure you have installed pyctree as described above.
Problem: sql.sqlalchemy can fail with "shared library not found."
Solution: Run one of the following:
setenv LD_LIBRARY_PATH /<PATH_TO_YOUR_CTREE_SERVER>/drivers/sql.python/
export LD_LIBRARY_PATH=<PATH_TO_YOUR_CTREE_SERVER>/drivers/sql.python/
The python tutorials currently use “127.0.0.1” to connect to the c-tree server on the local machine instead of using “localhost”. This is because Windows 10 often has “localhost” commented out of its “hosts” file (%systemroot%\System32\drivers\etc\hosts), as follows:
# localhost name resolution is handled within DNS itself.
#127.0.0.1 localhost
#::1 localhost
Unfortunately, Python does not seem to use DNS to resolve "localhost", which means that these tutorials are unable to connect to the c-tree server on some versions of Windows if they use “localhost” instead of “127.0.0.1”. By using “127.0.0.1” in our Python tutorials, we work around this problem.
If you are using IPv6, or have some other situation where “127.0.0.1” is not appropriate, feel free to update the call to create_engine() in the demonstration file, <faircom>\drivers\python.sql.sqlalchemy\tutorials\usage.py