### ARM v7 Wheel File Examples Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux.md Examples of wheel filenames for ARM v7 architecture and instructions to copy them to a prebuilt location. ```bash ######### ARM v7 # /work/t1/IfxPy/IfxPy/dist/IfxPy-3.0.1-cp27-cp27mu-linux_armv7l.whl # /work/t1/IfxPy/IfxPy/dist/IfxPy-3.0.1-cp35-cp35m-linux_armv7l.whl # Python 3.x wheel build to the prebuilt location for ARM v7 # cp /work/t1/IfxPy/IfxPy/dist/IfxPy-3.0.1-cp35-cp35m-linux_armv7l.whl /work/t1/IfxPy/prebuilt/3x/ARM/. # md5sum /work/t1/IfxPy/prebuilt/3x/ARM/IfxPy-3.0.1-cp35-cp35m-linux_armv7l.whl # You may use pip install to install the driver from the whl file # For example: # pip3 install /work/t1/IfxPy/prebuilt/3x/ARM/IfxPy-3.0.1-cp35-cp35m-linux_armv7l.whl # pip3 uninstall /work/t1/IfxPy/prebuilt/3x/ARM/IfxPy-3.0.1-cp35-cp35m-linux_armv7l.whl ``` -------------------------------- ### Database Setup Source: https://github.com/openinformix/ifxpy/blob/master/Examples/Sample1.ipynb Create a new database and a dedicated user with DBA privileges for the application. ```bash dbaccess sysmaster < Python 2.7.11 and it is installed in "/opt/csw/bin" ls -lrt /opt/csw/bin/py* ``` -------------------------------- ### Prepare for Local Build Test Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux.md Copy a sample Python script and remove any existing IfxPy.so files to prepare for testing a local build. ```bash cd /work/try/ cp /work/t1/IfxPy/Examples/Sample1.py Sample.py rm IfxPy.so # rm *.so ``` -------------------------------- ### Build IfxPy Driver Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildWindows.md Execute the build command for IfxPy using setup.py. This command is common for both Python 2.7 and 3.x builds. Output is redirected to out.txt. ```bash # common for Python 2.7 and 3.x cd C:\work\IfxPy\IfxPy python setup.py build > out.txt 2>&1 ``` -------------------------------- ### IfxPy.get_option Source: https://github.com/openinformix/ifxpy/blob/master/README.md Gets the specified option in the resource. ```APIDOC ## IfxPy.get_option ### Description Gets the specified option in the resource. ### Method Not specified (assumed to be a function call within the IfxPy module). ### Parameters Not specified in the source text. ``` -------------------------------- ### IfxPy.get_smart_trigger_session_id Source: https://github.com/openinformix/ifxpy/blob/master/README.md Get already opened Smart Trigger session ID ```APIDOC ## IfxPy.get_smart_trigger_session_id ### Description Get already opened Smart Trigger session ID. ### Method Not specified (assumed to be a function call within the IfxPy module). ### Parameters Not specified in the source text. ``` -------------------------------- ### Run IfxPy Sample Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux_v2.md Executes a sample Python script to test the IfxPy driver. This involves copying a sample file, editing connection information, and running the script with either python or python3. ```bash cd /work/try/ cp /work/t1/IfxPy/Examples/Sample1.py Sample.py # Edit Sample.py connection information, vi Sample.py # and then run the sample python Sample.py # or if Pythong 3.x python3 Sample.py ``` -------------------------------- ### Clean Build Directories Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux_v2.md Removes the build and distribution directories before starting a new build. ```bash cd /work/t1/IfxPy/IfxPy rm -rf /work/t1/IfxPy/IfxPy/build rm -rf /work/t1/IfxPy/IfxPy/dist ``` -------------------------------- ### Register Smart Trigger with Callback Functions Source: https://github.com/openinformix/ifxpy/blob/master/README.md This sample demonstrates how to set up and register smart triggers using multiple threads. It includes defining callback functions to handle trigger events and opening a smart trigger with specific parameters. ```python # test_SmartTrigger.py import IfxPy from ctypes import * import threading import os def printme1(outValue1): """This prints a passed string into this function1""" print ("\nTest for callback function, value = ", outValue1) return def printme2(outValue2): """This prints a passed string into this function2""" print ("\nTest for callback function, value = ", outValue2) return def task1(): print("Task 1 assigned to thread: {}".format(threading.current_thread().name)) print("ID of process running task 1: {}".format(os.getpid())) temp4 = IfxPy.register_smart_trigger_loop(conn, printme1, temp, "t1", "informix", "sheshdb", "select * from t1;", "label1", False, False) #temp4 = IfxPy.register_smart_trigger_loop(conn, printme1, temp, "बस", "informix", "sheshdb_utf8", "select * from बस;", "label1", False, False) def task2(): print("Task 2 assigned to thread: {}".format(threading.current_thread().name)) print("ID of process running task 2: {}".format(os.getpid())) #temp5 = IfxPy.register_smart_trigger_loop(conn, printme2, temp, "t2", "informix", "sheshdb", "select * from t2;", "label2", False, False) temp5 = IfxPy.register_smart_trigger_loop(conn, printme2, temp, "t2", "informix", "sheshdb_utf8", "select * from t2;", "label2", False, False) # if __name__ == "__main__": # ConStr = "SERVER=ol_informix1410;DATABASE=sheshdb_utf8;HOST=127.0.0.1;SERVICE=1067;UID=informix;PWD=xxxx;DB_LOCALE=en_us.utf8;CLIENT_LOCALE=en_us.UTF8;" ConStr = "SERVER=ol_informix1410;DATABASE=sheshdb;HOST=127.0.0.1;SERVICE=1067;UID=informix;PWD=xxx;" conn = IfxPy.connect( ConStr, "", "") temp = IfxPy.open_smart_trigger(conn, "Unique1", False, 5, 1, 0) print ("\nFile descriptor = ", temp) # creating threads t1 = threading.Thread(target=task1, name='t1') t2 = threading.Thread(target=task2, name='t2') # starting threads t1.start() t2.start() # wait until all threads finish t1.join() t2.join() IfxPy.close(conn) print ("Done") ``` -------------------------------- ### Get Cursor Type Source: https://github.com/openinformix/ifxpy/wiki/Home Retrieves the cursor type of an IFXStatement to determine if it's forward-only or scrollable. ```python int IfxPy.cursor_type ( IFXStatement stmt ) ``` -------------------------------- ### Display Thank You Message Source: https://github.com/openinformix/ifxpy/blob/master/Examples/cte.ipynb This snippet prints a thank you message to the console. It requires no special setup or imports. ```python print("Thank you!") ``` -------------------------------- ### Generate Julia Set in Python Source: https://github.com/openinformix/ifxpy/blob/master/Examples/cte.ipynb This Python code generates a Julia Set fractal image. It is a port from a PostgreSQL example. ```python # Query to generate a Julia Set (a beautiful tree like image) # port from PostgreSQL https://explainextended.com/2013/12/31/happy-new-year-5/ ``` -------------------------------- ### Executing a Simple SQL Query Source: https://github.com/openinformix/ifxpy/blob/master/Examples/cte.ipynb Demonstrates how to execute a simple SQL query and fetch results using IFXPY. This is a fundamental operation for data retrieval. ```python import ifxdb conn_str = "SERVER=ids_server;DATABASE=testdb;USERID=informix;PASSWORD=password" try: conn = ifxdb.connect(conn_str) cursor = conn.cursor() # Execute a query cursor.execute("SELECT first_name, last_name FROM customers WHERE customer_id = 101") # Fetch one row row = cursor.fetchone() if row: print(f"Customer Name: {row[0]} {row[1]}") cursor.close() conn.close() except ifxdb.Error as e: print(f"Error executing query: {e}") ``` -------------------------------- ### Update and Install pip for Python 2.7 Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux_v2.md Installs/upgrades pip for Python 2.7. Ensure pip version 10.0.1 or higher is used. ```bash ##### if python 2.7 #sudo apt install python-pip pip install --upgrade pip pip --version ``` -------------------------------- ### Legacy Build Process Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux_v2.md Performs a legacy build of the IfxPy driver without using wheel packages. This method is not recommended. It involves cleaning the build directory and running 'setup.py build'. ```bash cd /work/t1/IfxPy/IfxPy rm -rf build # '/work/dev/Python' has added to the path, then # export PATH=/work/dev/Python:$PATH # $ which python # /work/dev/Python/python # pip install setuptools python setup.py build > out.txt 2>&1 #python3 setup.py build > out.txt 2>&1 # if all go well, then Informix native python driver will be at # if Linux x86_64bit with Python 2.7 build then ls -l ./build/lib.linux-x86_64-2.7/IfxPy.so # if ARM v7 with Python 2.7 then ls -l build/lib.linux-armv7l-2.7/IfxPy.so # if Linux x86_64bit with Python 3.x build then # ls -l ./build/lib.linux-x86_64-3.5/IfxPy.cpython-35m-x86_64-linux-gnu.so # on armv7 with Python 3.x # ls -l ls ./build/lib.linux-armv7l-3.5/IfxPy.cpython-35m-arm-linux-gnueabihf.so ``` -------------------------------- ### Logon to the VM Source: https://github.com/openinformix/ifxpy/blob/master/Examples/Sample1.ipynb Connect to the Informix server VM using SSH and switch to the informix user. ```bash ssh demo1@168.61.54.126 # Switch to user informix sudo -u informix bash ``` -------------------------------- ### Get Informix Statement Cursor Type Source: https://github.com/openinformix/ifxpy/blob/master/README.IfxPyAPI.md Retrieves the cursor type used by an IFXStatement. This helps determine if the cursor is forward-only or scrollable. ```python cursor_type = IfxPy.cursor_type(stmt) ``` -------------------------------- ### Deleting Data from a Table Source: https://github.com/openinformix/ifxpy/blob/master/Examples/cte.ipynb This example shows how to delete records from an Informix table using IFXPY. Parameter binding is crucial for safe deletion. ```python import ifxdb conn_str = "SERVER=ids_server;DATABASE=testdb;USERID=informix;PASSWORD=password" try: conn = ifxdb.connect(conn_str) cursor = conn.cursor() # ID of the record to delete customer_id_to_delete = 102 # SQL statement with placeholder sql = "DELETE FROM customers WHERE customer_id = ?" # Execute the delete statement with data cursor.execute(sql, (customer_id_to_delete,)) conn.commit() # Commit the transaction print(f"Customer ID {customer_id_to_delete} deleted successfully.") cursor.close() conn.close() except ifxdb.Error as e: print(f"Error deleting data: {e}") if conn: conn.rollback() # Rollback on error ``` -------------------------------- ### Display Employee Hierarchy Image Source: https://github.com/openinformix/ifxpy/blob/master/Examples/cte.ipynb Displays an image representing the employee hierarchy, likely used in conjunction with the following recursive CTE example. ```python from IPython.display import display, Image display(Image(filename='employee.png')) ``` -------------------------------- ### Insert Data with Parameter Binding Source: https://github.com/openinformix/ifxpy/blob/master/README.md Demonstrates inserting data using prepared statements and parameter binding with basic data types like INTEGER and CHAR. Use IfxPy.bind_param to associate Python variables with SQL parameters and IfxPy.execute to run the statement. ```python # Sample2.py import IfxPy def my_Sample(): ConStr = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxxx;" try: # netstat -a | findstr 9088 conn = IfxPy.connect( ConStr, "", "") except Exception as e: print ('ERROR: Connect failed') print ( e ) quit() try: sql = "drop table t1;" print ( sql ) stmt = IfxPy.exec_immediate(conn, sql) except: print ('FYI: drop table failed') sql = "create table t1 ( c1 int, c2 char(20), c3 int, c4 int ) ;" stmt = IfxPy.exec_immediate(conn, sql) sql = "INSERT INTO t1 (c1, c2, c3, c4) VALUES ( ?, ?, ?, ? )" stmt = IfxPy.prepare(conn, sql) c1 = None c2 = None c3 = None c4 = None # Create bindings for the parameter IfxPy.bind_param(stmt, 1, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER) IfxPy.bind_param(stmt, 2, c2, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_CHAR) IfxPy.bind_param(stmt, 3, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER) IfxPy.bind_param(stmt, 4, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER) print("Inserting Recors ……") i = 0 while i < 10: i += 1 c1 = 100 + i c2 = "Testing {0}".format(i) c3 = 20000 + i c4 = 50000 + i # supply new values as a tuple IfxPy.execute(stmt, (c1, c2, c3, c4) ) # Try select those rows we have just inserted print("Selecting Recors ……") sql = "SELECT * FROM t1" stmt = IfxPy.exec_immediate(conn, sql) tu = IfxPy.fetch_tuple(stmt) rc = 0 while tu != False: rc += 1 print( tu ) tu = IfxPy.fetch_tuple(stmt) print() print( "Total Record Inserted {}".format(i) ) print( "Total Record Selected {}".format(rc) ) # Free up memory used by result and then stmt too IfxPy.free_result(stmt) IfxPy.free_stmt (stmt) # close the connection IfxPy.close(conn) print ("Done") ####### Run the sample function ###### my_Sample() ``` -------------------------------- ### Configure and Build Python 3.7.1 from Source (UCS4) Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux_v2.md Downloads, extracts, and configures Python 3.7.1 source code for UCS4 Unicode encoding. Assumes build environment is set up in /work/dev. ```bash cd /work/dev rm ./Python sudo rm -rf ./Python-3.7.1 wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz tar zxvf Python-3.7.1.tgz ln -s ./Python-3.7.1 ./Python cd /work/dev/Python sudo ./configure --enable-unicode=ucs4 ``` -------------------------------- ### Upgrade Build Tools for Python 3.x Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux.md Upgrades setuptools, wheel, and twine to their latest versions for Python 3.x builds. ```bash # if python 3.x sudo pip3 install setuptools --upgrade sudo pip3 install wheel --upgrade sudo pip3 install twine --upgrade pip3 install --upgrade pip ``` -------------------------------- ### Map Visual Studio Version for Python 2.7 Build Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildWindows.md When building with Python 2.7, setup.py looks for Visual Studio 2008. Map the VSxxCOMNTOOLS variable to VS90COMNTOOLS if you are using a different version of Visual Studio. ```bash #For example: #If you are using Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS% #If you are using Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS% #If you are using Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS% #If you are using Visual Studio 2015 (VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS% #If you are using Visual Studio 2017 (VS15): SET VS90COMNTOOLS=%VS150COMNTOOLS% ``` -------------------------------- ### Update and Install pip for Python 3 Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildLinux_v2.md Updates system packages and installs/upgrades pip for Python 3. Ensure pip version 10.0.1 or higher is used. ```bash sudo apt update #### For Python 3 # sudo apt install python3-pip # python3 -m pip install --upgrade pip # sudo python3 -m pip uninstall pip pip3 install --upgrade pip pip3 --version ``` -------------------------------- ### Clone IfxPy Repository Source: https://github.com/openinformix/ifxpy/blob/master/TmpInstallFromPrebuiltBinary.md Clone the IfxPy repository to access prebuilt driver binaries. This is a common first step for both Python 2.7 and Python 3.x installations. ```bash git clone https://github.com/OpenInformix/IfxPy.git ``` -------------------------------- ### Copy Prebuilt Driver Binary Zip (Python 3.x) Source: https://github.com/openinformix/ifxpy/blob/master/LocalBuildWindows.md Copies a prebuilt driver binary zip file for Python 3.x. This can then be unzipped. ```bash COPY C:\work\IfxPy\prebuilt\3x\Win64\IfxPy.zip # then unzip it ``` -------------------------------- ### Inserting Data into a Table Source: https://github.com/openinformix/ifxpy/blob/master/Examples/cte.ipynb This example shows how to insert new data into an Informix table using IFXPY. It includes parameter binding to prevent SQL injection. ```python import ifxdb conn_str = "SERVER=ids_server;DATABASE=testdb;USERID=informix;PASSWORD=password" try: conn = ifxdb.connect(conn_str) cursor = conn.cursor() # Data to insert new_customer_data = ('John', 'Doe', 'john.doe@example.com') # SQL statement with placeholders sql = "INSERT INTO customers (first_name, last_name, email) VALUES (?, ?, ?)" # Execute the insert statement with data cursor.execute(sql, new_customer_data) conn.commit() # Commit the transaction print("New customer inserted successfully.") cursor.close() conn.close() except ifxdb.Error as e: print(f"Error inserting data: {e}") if conn: conn.rollback() # Rollback on error ```