├── testCacheBinding ├── sample_Person_cache_query_class.py ├── sample_Person_cache_query_sql.py ├── sample_CacheException.py ├── sample_Person_cache_object.py └── testCachePython Binding.ipynb ├── testSocket.py ├── socket.py ├── __init__.py ├── README.md ├── testCacheORM ├── testCacheORM - Cache Objects Test 1.ipynb ├── testCacheORM - Cache Objects Test 2.ipynb └── testCacheORM - Cache Queries.ipynb ├── LICENSE └── cacheorm.py /testCacheBinding/sample_Person_cache_query_class.py: -------------------------------------------------------------------------------- 1 | # Demo of Intersystems Cache Python binding with Samples namespace and Sample.Person class 2 | import intersys.pythonbind3 3 | 4 | # Create a connection to SAMPLES namespace 5 | user="_SYSTEM"; 6 | password="123"; 7 | host = "localhost"; 8 | port = "1972"; 9 | url = host+"["+port+"]:SAMPLES" 10 | conn = intersys.pythonbind3.connection( ) 11 | conn.connect_now(url, user, password, None) 12 | samplesDB = intersys.pythonbind3.database(conn) 13 | 14 | # create a query 15 | cq = intersys.pythonbind3.query(samplesDB) 16 | cq.prepare_class("Sample.Person", "ByName") 17 | cq.set_par(1,"A") 18 | 19 | #%% 20 | # Execute and fetch rows 21 | cq.execute() 22 | for x in range(0,8): 23 | print(cq.fetch([None])) 24 | -------------------------------------------------------------------------------- /testCacheBinding/sample_Person_cache_query_sql.py: -------------------------------------------------------------------------------- 1 | # Demo of Intersystems Cache Python binding with Samples namespace and Sample.Person class 2 | import intersys.pythonbind3 3 | 4 | # version of Caché running on the Python client machine 5 | print(intersys.pythonbind3.get_client_version()) 6 | 7 | #%% 8 | # Create a connection 9 | user="_SYSTEM"; 10 | password="123"; 11 | host = "localhost"; 12 | port = "1972"; 13 | url = host+"["+port+"]:SAMPLES" 14 | conn = intersys.pythonbind3.connection() 15 | 16 | # Connect Now to SAMPLES namespace 17 | conn.connect_now(url, user, password, None) 18 | 19 | # Create a database object 20 | samplesDB = intersys.pythonbind3.database(conn) 21 | 22 | #%% 23 | # create a query object 24 | cq = intersys.pythonbind3.query(samplesDB) 25 | 26 | # prepare and execute query 27 | sql = "SELECT ID, Name, DOB, SSN FROM Sample.Person" 28 | cq.prepare(sql) 29 | cq.execute() 30 | 31 | # Fetch rows 32 | for x in range(0,10): 33 | print(cq.fetch([None])) 34 | 35 | -------------------------------------------------------------------------------- /testSocket.py: -------------------------------------------------------------------------------- 1 | 2 | #%% ************************************************** 3 | #%% First terminal (receiver) 4 | 5 | from socket import SocketReceiver 6 | 7 | socket_receiver = SocketReceiver(host='localhost', port=5005) 8 | 9 | print(socket_receiver) 10 | 11 | socket_receiver.listen(1024) 12 | 13 | #%% 14 | # How to set an Intersystems CACHE listener 15 | # at a console enter the following commands 16 | # set tcp="|TCP|5005|" 17 | # open tcp:(:5005):1 write $s($t:"OK", 1:"failed"),! 18 | # for line=1:1 use tcp read text use 0 write line, ?5, text, ! 19 | 20 | #%% ************************************************** 21 | #%% Second terminal (client) 22 | 23 | from socket import SocketSender 24 | 25 | socket_sender = SocketSender(host='localhost', port=4200) 26 | 27 | print(socket_sender) 28 | 29 | socket_sender.connect() 30 | 31 | #%% Start sending string messages 32 | 33 | socket_sender.send('Hello world') 34 | socket_sender.send('Do you copy ???') 35 | 36 | 37 | #%% Test with Intersystems Cache Python Binding 38 | import intersys.pythonbind3 39 | 40 | conn = intersys.pythonbind3.connection( ) 41 | conn.connect_now('localhost[1972]:SAMPLES', '_SYSTEM', '123', None) 42 | samplesDB = intersys.pythonbind3.database(conn) 43 | samplesDB.run_class_method("Sample.Person", "SendMessage", ["Hello world", 5005]) 44 | -------------------------------------------------------------------------------- /testCacheBinding/sample_CacheException.py: -------------------------------------------------------------------------------- 1 | from intersys import pythonbind3 2 | import sys 3 | 4 | user="_SYSTEM" 5 | password="1233" 6 | host = "localhost" 7 | port = "1972" 8 | 9 | def print_exception(err): 10 | print() 11 | print(' ********** InterSystems Cache exception ********** ') 12 | print('Exception Type : ',sys.exc_info()[0]) 13 | print('Exception Value : ',sys.exc_info()[1]) 14 | print('Exception Traceback : ',sys.exc_info()[2]) 15 | print(' ************************************************** ') 16 | print('Exception Error : ',str(err)) 17 | 18 | #%% 19 | try: 20 | url = host+"["+port+"]:SAMPLES" 21 | conn = pythonbind3.connection( ) 22 | conn.connect_now(url, user, password, None) 23 | database = pythonbind3.database( conn) 24 | person = database.create_new("Sample.Person", None) 25 | person.set("Name","Doe, Joe A") 26 | 27 | # Save instance of Person 28 | person.run_obj_method("%Save",[]) 29 | 30 | # Create a new instance of Sample.Person to be spouse 31 | spouse = database.create_new("Sample.Person", None) 32 | spouse.set("Name","Doe, Mary") 33 | person.set("Spouse",spouse) 34 | person.run_obj_method("%Save",[]) 35 | 36 | # Save instance of Person 37 | spouse.set("Spouse",person) 38 | spouse.run_obj_method("%Save",[]) 39 | 40 | print("Sample finished running") 41 | except pythonbind3.cache_exception as err: 42 | print_exception(err) -------------------------------------------------------------------------------- /socket.py: -------------------------------------------------------------------------------- 1 | import socket 2 | 3 | class SocketSender: 4 | 5 | def __init__(self, host='localhost', port=9999): 6 | self.host=host 7 | self.port=port 8 | 9 | # Create a client socket 10 | self.client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 11 | 12 | def __repr__(self): 13 | return f'SocketSender({self.host}, {self.port})' 14 | 15 | def connect(self): 16 | self.client.connect((self.host, self.port)) 17 | print(f"Client connected successfully to {self.host} at port {self.port}") 18 | 19 | def send(self, msg): 20 | msgbytes = bytearray(msg, 'utf-8') 21 | totalsent = 0 22 | MSGLEN = len(msgbytes) 23 | while totalsent < MSGLEN: 24 | sent = self.client.send(msgbytes[totalsent:]) 25 | if sent == 0: 26 | raise RuntimeError("socket connection broken") 27 | totalsent = totalsent + sent 28 | 29 | 30 | class SocketReceiver: 31 | def __init__(self, host='127.0.0.1', port=9999): 32 | self.host = host 33 | self.port = port 34 | 35 | # Create a server socket and bind it to host on port 9999 36 | self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 37 | self.server.bind((self.host, self.port)) 38 | 39 | def __repr__(self): 40 | return f'SocketReceiver({self.host}, {self.port})' 41 | 42 | def listen(self, bufsize): 43 | self.server.listen(1) 44 | print('Server is listening at port ',self.port) 45 | 46 | # Establish connection with client. 47 | conn, addr = self.server.accept() 48 | print('Connection from: ' + str(addr)) 49 | 50 | while True: 51 | data = conn.recv(bufsize).decode() 52 | if not data: 53 | break 54 | print ("--> " + str(data)) 55 | 56 | # Close the connection with the client 57 | conn.close() 58 | 59 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | This module is an enhanced OOP porting of Intersystems Cache-Python binding. 3 | It serves the purpose of an object-relational mapper in python for Intersystems Cache database 4 | There are three classes implemented: 5 | 6 | CacheClient: 7 | This is the super class of CachePython module. 8 | It wraps two functions from intersys.pythonbind module 9 | pythonbind3.connection() and pythonbind3.database(). 10 | 11 | CacheQuery: 12 | A subclass of CacheClient that wraps methods and adds extra functionality in 13 | intersys.pythonbind.database and intersys.pythonbind.query classes 14 | 15 | CacheClass: 16 | A subclass of CacheClient, that wraps methods and adds extra functionality in 17 | intersys.pythonbind.database and intersys.pythonbind.object classes 18 | 19 | The intersys.pythonbind package is a Python C extension that provides Python 20 | application with transparent connectivity to the objects stored in the Caché database. 21 | 22 | The Caché Object Server, a high performance server process, manages communication 23 | between Python clients and a Caché database server. It communicates using standard 24 | networking protocols (TCP/IP), and can run on any platform supported by Caché. 25 | """ 26 | 27 | __version__ = '0.10.0' 28 | __version_update__ = '2018-01-06' 29 | __version_modifications__ ='' 30 | 31 | __release_version__ = '0.9.0' 32 | __release_date__ = '2018-07-23' 33 | __release_changes__='' 34 | __source_url__='' 35 | 36 | __project_started__ = '2017-08-01' 37 | __python_version__ = '>=3.6.0' 38 | __cache_version__ = '2017.1.1.111.0' 39 | __platform__ = 'Linux' 40 | 41 | __author__ = 'Athanassios I. Hatzis' 42 | __author_email = 'hatzis@healis.eu' 43 | __organization__="HEALIS (Healthy Information Systems/Services)" 44 | __organization_url="http://healis.eu" 45 | __copyright__ = "Copyright (c) 2017,2018 Athanassios I. Hatzis" 46 | __license__ = " " 47 | __distributor__='Promoted and Distributed by HEALIS' 48 | __distributor_url__='http://healis.eu' 49 | __maintainer__='Athanassios I. Hatzis' 50 | __maintainer_email__='hatzis@healis.eu' 51 | __status__='Production' 52 | 53 | 54 | from CacheORM.cacheorm import CacheQuery, CacheClass 55 | 56 | from CacheORM.socket import SocketSender, SocketReceiver 57 | -------------------------------------------------------------------------------- /testCacheBinding/sample_Person_cache_object.py: -------------------------------------------------------------------------------- 1 | # Demo of Intersystems Cache Python binding with Samples namespace and Sample.Person class 2 | import intersys.pythonbind3 3 | 4 | conn = intersys.pythonbind3.connection( ) 5 | conn.connect_now('localhost[1972]:SAMPLES', '_SYSTEM', '123', None) 6 | samplesDB = intersys.pythonbind3.database(conn) 7 | 8 | #%% Create a new instance of Sample.Person to be husband 9 | husband = samplesDB.create_new("Sample.Person", None) 10 | ssn1 = samplesDB.run_class_method("%Library.PopulateUtils","SSN",[]) 11 | dob1 = samplesDB.run_class_method("%Library.PopulateUtils","Date",[]) 12 | husband.set("Name","Hatzis, Athanassios I") 13 | husband.set("SSN",ssn1) 14 | husband.set("DOB",dob1) 15 | 16 | # Save husband 17 | husband.run_obj_method("%Save",[]) 18 | print ("Saved id: "+str(husband.run_obj_method("%Id",[]))) 19 | 20 | #%% Create a new instance of Sample.Person to be wife 21 | wife = samplesDB.create_new("Sample.Person", None); 22 | ssn2 = samplesDB.run_class_method("%Library.PopulateUtils","SSN",[]) 23 | dob2 = samplesDB.run_class_method("%Library.PopulateUtils","Date",[]) 24 | wife.set("Name","Kalamari, Panajota"); 25 | wife.set("SSN",ssn2) 26 | wife.set("DOB",dob2) 27 | 28 | # Save wife 29 | wife.set("Spouse",husband); 30 | wife.run_obj_method("%Save",[]); 31 | print ("Saved id: " + str(wife.run_obj_method("%Id",[]))) 32 | 33 | #%% Relate them 34 | husband.set("Spouse",wife); 35 | husband.run_obj_method("%Save",[]); 36 | 37 | wife.set("Spouse",husband); 38 | wife.run_obj_method("%Save",[]); 39 | 40 | #%% 41 | # check if ID exists in the database by defining a function 42 | def CheckID(db,id): 43 | if not db.run_class_method("Sample.Person","%ExistsId",[str(id)]): 44 | print("There is no person with id "+ str(id) + " in the database." ) 45 | return 0 46 | else: 47 | print('OK, ID exists') 48 | return 1 49 | 50 | # Open an instance of the Sample.Person object 51 | athanID=217 52 | if CheckID(samplesDB,athanID): 53 | athanPerson = samplesDB.openid("Sample.Person",str(athanID),-1,-1) 54 | 55 | # Open another instance 56 | otherID=3 57 | otherPerson = samplesDB.openid("Sample.Person",str(otherID),-1,-1) 58 | 59 | # Fetch some properties 60 | print ("ID: " + otherPerson.run_obj_method("%Id",[])) 61 | print ("Name: " + otherPerson.get("Name")) 62 | print ("SSN: " + otherPerson.get("SSN")) 63 | print ("DOB: " + str(otherPerson.get("DOB"))) 64 | print ("Age: " + str(otherPerson.get("Age"))) 65 | 66 | #Attempt to bring in an embedded object 67 | addr = otherPerson.get("Home"); 68 | print ("Street: " + addr.get("Street")) 69 | print ("City: " + addr.get("City")) 70 | print ("State: " + addr.get("State")) 71 | print ("Zip: " + addr.get("Zip")) 72 | print ("Sample finished running") 73 | 74 | -------------------------------------------------------------------------------- /testCacheBinding/testCachePython Binding.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Test Cache-Python Binding" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [ 15 | { 16 | "data": { 17 | "text/html": [ 18 | "" 19 | ], 20 | "text/plain": [ 21 | "" 22 | ] 23 | }, 24 | "metadata": {}, 25 | "output_type": "execute_result" 26 | } 27 | ], 28 | "source": [ 29 | "from IPython.core.display import display, HTML\n", 30 | "display(HTML(\"\"))" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "metadata": { 37 | "collapsed": true 38 | }, 39 | "outputs": [], 40 | "source": [ 41 | "# Demo of Intersystems Cache Python binding with Samples namespace and Sample.Person class\n", 42 | "import intersys.pythonbind3" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "metadata": { 49 | "collapsed": true 50 | }, 51 | "outputs": [], 52 | "source": [ 53 | "conn = intersys.pythonbind3.connection( )\n", 54 | "conn.connect_now('localhost[1972]:SAMPLES', '_SYSTEM', 'SYS', None)\n", 55 | "samplesDB = intersys.pythonbind3.database(conn)" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": 3, 61 | "metadata": { 62 | "collapsed": true 63 | }, 64 | "outputs": [], 65 | "source": [ 66 | "#Create a new instance of Sample.Person\n", 67 | "partner = samplesDB.create_new(\"Sample.Person\", None)\n", 68 | "ssn1 = samplesDB.run_class_method(\"%Library.PopulateUtils\",\"SSN\",[])\n", 69 | "dob1 = samplesDB.run_class_method(\"%Library.PopulateUtils\",\"Date\",[])\n", 70 | "partner.set(\"Name\",\"Sekros, Zissis\")\n", 71 | "partner.set(\"SSN\",ssn1)\n", 72 | "partner.set(\"DOB\",dob1)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "code", 77 | "execution_count": null, 78 | "metadata": { 79 | "collapsed": true 80 | }, 81 | "outputs": [], 82 | "source": [ 83 | "# Save partner\n", 84 | "partner.run_obj_method(\"%Save\",[])\n", 85 | "print (\"Saved id: \"+str(partner.run_obj_method(\"%Id\",[])))" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": null, 91 | "metadata": { 92 | "collapsed": true 93 | }, 94 | "outputs": [], 95 | "source": [] 96 | } 97 | ], 98 | "metadata": { 99 | "kernelspec": { 100 | "display_name": "Python 3", 101 | "language": "python", 102 | "name": "python3" 103 | }, 104 | "language_info": { 105 | "codemirror_mode": { 106 | "name": "ipython", 107 | "version": 3 108 | }, 109 | "file_extension": ".py", 110 | "mimetype": "text/x-python", 111 | "name": "python", 112 | "nbconvert_exporter": "python", 113 | "pygments_lexer": "ipython3", 114 | "version": "3.6.3" 115 | } 116 | }, 117 | "nbformat": 4, 118 | "nbformat_minor": 2 119 | } 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IntersystemsCacheORM 2 | Intersystems Cache Object-Relational Mapper based on [Intersystems Python Binding][4] module. 3 | 4 | ### About CacheORM 5 | This module is an enhanced OOP porting of Intersystems [Cache-Python binding][1]. It serves the purpose of an object-relational mapper in python for Intersystems Cache database There are three classes implemented: 6 | 7 | * **CacheClient** 8 | This is the super class of CachePython module. It wraps two functions from intersys.pythonbind module [pythonbind3.connection()][3] and [pythonbind3.database()][6]. 9 | 10 | * **CacheQuery** 11 | A subclass of CacheClient that wraps methods and adds extra functionality in [intersys.pythonbind.database][6] and [intersys.pythonbind.query][2] classes 12 | 13 | * **CacheClass** 14 | A subclass of CacheClient, that wraps methods and adds extra functionality in [intersys.pythonbind.database][6] and [intersys.pythonbind.object][5] classes 15 | 16 | The [intersys.pythonbind package][4] is a Python C extension that provides Python application with transparent connectivity to the objects stored in the Caché database. 17 | 18 | The Caché Object Server, a high performance server process, manages communication between Python clients and a Caché database server. It communicates using standard networking protocols (TCP/IP), and can run on any platform supported by Caché. 19 | 20 | ### Source Code 21 | Open and view [cacheorm.py][8] 22 | The code released here was originally written and used as a module of [TRIADB][11] project. 23 | 24 | ### Tests and Demos 25 | There are two folders in this release: 26 | 27 | * testCacheORM contains python jupyter notebook files that demonstrate CacheQuery and CacheClass 28 | * testCacheBinding are tests written for Intersystems Cache python binding 29 | 30 | One can simply compare tests with demos to appreciate the work in this project to leverage intersystems cache python binding. 31 | 32 | ### Documentation 33 | Currently there is no documentation written for the project. Python jupyter notebooks in testCacheORM folder demonstrate the use of CacheQuery and CacheClass. You may also study the code that is well commented (see [cacheorm.py][8]). 34 | 35 | ### Bonus 36 | I wrote these [SocketReceiver, SocketSender][7] classes for Python 3 so now it is super easy for anyone to run a simple TCP socket communication test on two Python consoles. This was done in order to capture "writes" from Caché. In that case you need to redirect your IO and write the data to python console. 37 | 38 | ### Installation 39 | Caché provides client-side Python support through the `intersys.pythonbind` module, which implements the connection and caching mechanisms required to communicate with a Caché server. This module **must be compiled and installed in your environment**. Set up your environment variables to support C compilation and linking, as described in the [installation guide of Intersystems Cache Python Binding][12]. Also make sure that you are using Python 3 interpreter when you run the setup. 40 | 41 | If installation is successful the module will be placed under your python site-packages in a folder with the name `pythonbind3-1.0-py3.6-linux-x86_64.egg`. Now you may run any of the [sample programs][13] that are provided by Intersystems Cache to verify that Python interpreter references properly `intersys.pythonbind` module. 42 | 43 | If you passed successfully this stage then download CacheORM, unzip it and rename the folder as `CacheORM`. Locate your Python 3 installation and copy the folder under `site-packages` e.g. `../lib/python3.6/site-packages/CacheORM/` 44 | 45 | Finally try to execute my tests and demos. I have also placed jupyter notebook files at [my Microsoft Azure library][14] and you can **ONLY view them or download and open them locally at your machine** (I think you must login first). 46 | 47 | [1]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_using 48 | [2]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_classes#GBPY_classes_queries 49 | [3]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_using#GBPY_using_basics 50 | [4]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY 51 | [5]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_classes#GBPY_classes_objects 52 | [6]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_classes#GBPY_classes_database 53 | [7]: https://github.com/healiseu/IntersystemsCacheORM/blob/master/socket.py 54 | [8]: https://github.com/healiseu/IntersystemsCacheORM/blob/master/cacheorm.py 55 | [9]: https://github.com/healiseu/IntersystemsCacheORM/blob/master/testCacheORM/testCacheORM%20-%20Cache%20Objects%20Test%201.ipynb 56 | [10]: https://github.com/healiseu/IntersystemsCacheORM/blob/master/testCacheORM/testCacheORM%20-%20Cache%20Objects%20Test%202.ipynb 57 | [11]: http://healis.eu/triadb 58 | [12]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_intro#GBPY_intro_install 59 | [13]: https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GBPY_intro#GBPY_intro_samples 60 | [14]: https://notebooks.azure.com/athanassios/libraries/CacheORM 61 | -------------------------------------------------------------------------------- /testCacheORM/testCacheORM - Cache Objects Test 1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Demo of CacheORM Module - Cache Objects Test 1" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": { 14 | "collapsed": true 15 | }, 16 | "outputs": [], 17 | "source": [ 18 | "from CacheORM import CacheClass" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": {}, 24 | "source": [ 25 | "## Create a CacheInstance object" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 2, 31 | "metadata": {}, 32 | "outputs": [ 33 | { 34 | "name": "stdout", 35 | "output_type": "stream", 36 | "text": [ 37 | "Cache Python Object-Relational Mapper Module : \n", 38 | "Enhanced OOP porting of Intersystems Cache python binding modules\n", 39 | "(C) 2017-2018 HEALIS.EU - Athanassios I. Hatzis\n", 40 | "\n", 41 | "GNU Lesser General Public License v3.0\n", 42 | "\n", 43 | "CACHE Connection object to SAMPLES is created successfully.\n", 44 | "CACHE Connection Implementation Version : 1.0.1\n", 45 | "CACHE Database object is created successfully\n", 46 | "CACHE Class object is created successfully\n", 47 | "CACHE Instance object is created successfully\n" 48 | ] 49 | }, 50 | { 51 | "data": { 52 | "text/plain": [ 53 | "CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', '188')" 54 | ] 55 | }, 56 | "execution_count": 2, 57 | "metadata": {}, 58 | "output_type": "execute_result" 59 | } 60 | ], 61 | "source": [ 62 | "person = CacheClass(username='_SYSTEM', password='SYS', objectID='188', dl=99)\n", 63 | "person" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 3, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "CacheClass(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='SAMPLES', cacheclass='SAMPLES.Sample.Person', objectID='188')\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "print(person)" 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": 4, 86 | "metadata": {}, 87 | "outputs": [ 88 | { 89 | "name": "stdout", 90 | "output_type": "stream", 91 | "text": [ 92 | "CACHE_Object : \n", 93 | "CACHE_Database : \n", 94 | "CACHE_Connection : \n" 95 | ] 96 | } 97 | ], 98 | "source": [ 99 | "print(person.private_attributes)" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "## Get Cache object properties" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 5, 112 | "metadata": {}, 113 | "outputs": [ 114 | { 115 | "name": "stdout", 116 | "output_type": "stream", 117 | "text": [ 118 | "ID:188\n", 119 | "SSN: 214-80-9483\n", 120 | "Name:Chang,Stavros P.\n", 121 | "DateOfBirth:1982-03-08\n" 122 | ] 123 | } 124 | ], 125 | "source": [ 126 | "print(f\"ID:{person.id}\\nSSN: {person.get('SSN')}\\nName:{person.get('Name')}\\nDateOfBirth:{person.get('DOB')}\")" 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": {}, 132 | "source": [ 133 | "## Call Cache object method" 134 | ] 135 | }, 136 | { 137 | "cell_type": "code", 138 | "execution_count": 6, 139 | "metadata": {}, 140 | "outputs": [ 141 | { 142 | "data": { 143 | "text/plain": [ 144 | "3" 145 | ] 146 | }, 147 | "execution_count": 6, 148 | "metadata": {}, 149 | "output_type": "execute_result" 150 | } 151 | ], 152 | "source": [ 153 | "person.object_method(\"Addition\",1,2)" 154 | ] 155 | }, 156 | { 157 | "cell_type": "markdown", 158 | "metadata": {}, 159 | "source": [ 160 | "## Call Cache built-in class method " 161 | ] 162 | }, 163 | { 164 | "cell_type": "code", 165 | "execution_count": 7, 166 | "metadata": { 167 | "collapsed": true 168 | }, 169 | "outputs": [], 170 | "source": [ 171 | "populateUtils = CacheClass(namespace='%SYS', \n", 172 | " cachepackage='%Library', cacheclass='PopulateUtils', \n", 173 | " username='_SYSTEM', password='SYS')" 174 | ] 175 | }, 176 | { 177 | "cell_type": "code", 178 | "execution_count": 8, 179 | "metadata": {}, 180 | "outputs": [ 181 | { 182 | "data": { 183 | "text/plain": [ 184 | "['735-50-8916',\n", 185 | " '453-58-5043',\n", 186 | " '375-46-4034',\n", 187 | " '850-53-4304',\n", 188 | " '685-78-9306',\n", 189 | " '384-68-4009',\n", 190 | " '167-60-6261']" 191 | ] 192 | }, 193 | "execution_count": 8, 194 | "metadata": {}, 195 | "output_type": "execute_result" 196 | } 197 | ], 198 | "source": [ 199 | "[populateUtils.class_method(\"SSN\") for cnt in range(7)]" 200 | ] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "## Open 10 Instances and read their names" 207 | ] 208 | }, 209 | { 210 | "cell_type": "code", 211 | "execution_count": 9, 212 | "metadata": {}, 213 | "outputs": [ 214 | { 215 | "data": { 216 | "text/plain": [ 217 | "['Vanzetti,Lawrence B.',\n", 218 | " 'Bachman,Keith Q.',\n", 219 | " 'Murray,Bart N.',\n", 220 | " \"O'Rielly,Frances P.\",\n", 221 | " 'Cunningham,Natasha V.',\n", 222 | " 'Yoders,Lawrence B.',\n", 223 | " 'Ironhorse,Ed T.',\n", 224 | " 'Xiang,Agnes Z.',\n", 225 | " 'Chang,Stavros P.',\n", 226 | " 'Ott,Aviel Q.']" 227 | ] 228 | }, 229 | "execution_count": 9, 230 | "metadata": {}, 231 | "output_type": "execute_result" 232 | } 233 | ], 234 | "source": [ 235 | "[CacheClass(username='_SYSTEM', password='SYS', objectID=str(i)).get('Name') for i in range(180, 190)]" 236 | ] 237 | }, 238 | { 239 | "cell_type": "code", 240 | "execution_count": null, 241 | "metadata": { 242 | "collapsed": true 243 | }, 244 | "outputs": [], 245 | "source": [] 246 | } 247 | ], 248 | "metadata": { 249 | "kernelspec": { 250 | "display_name": "Python 3", 251 | "language": "python", 252 | "name": "python3" 253 | }, 254 | "language_info": { 255 | "codemirror_mode": { 256 | "name": "ipython", 257 | "version": 3 258 | }, 259 | "file_extension": ".py", 260 | "mimetype": "text/x-python", 261 | "name": "python", 262 | "nbconvert_exporter": "python", 263 | "pygments_lexer": "ipython3", 264 | "version": "3.6.3" 265 | } 266 | }, 267 | "nbformat": 4, 268 | "nbformat_minor": 2 269 | } 270 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /testCacheORM/testCacheORM - Cache Objects Test 2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Demo of CacheORM Module - Cache Objects Test 2" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 2, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from CacheORM import CacheClass" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Create an instance of PopulateUtils to call built-in CACHE class method " 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 3, 29 | "metadata": { 30 | "collapsed": true 31 | }, 32 | "outputs": [], 33 | "source": [ 34 | "populateUtils = CacheClass(namespace='%SYS', \n", 35 | " cachepackage='%Library', cacheclass='PopulateUtils', \n", 36 | " username='_SYSTEM', password='SYS')" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 4, 42 | "metadata": {}, 43 | "outputs": [ 44 | { 45 | "data": { 46 | "text/plain": [ 47 | "CacheClass(localhost, 1972, _SYSTEM, SYS, %SYS, '%SYS.%Library.PopulateUtils', 'No Object Set')" 48 | ] 49 | }, 50 | "execution_count": 4, 51 | "metadata": {}, 52 | "output_type": "execute_result" 53 | } 54 | ], 55 | "source": [ 56 | "populateUtils" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": {}, 62 | "source": [ 63 | "## Create CacheClass instance" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "metadata": {}, 70 | "outputs": [ 71 | { 72 | "name": "stdout", 73 | "output_type": "stream", 74 | "text": [ 75 | "Cache Python Object-Relational Mapper Module : \n", 76 | "Enhanced OOP porting of Intersystems Cache python binding modules\n", 77 | "(C) 2017-2018 HEALIS.EU - Athanassios I. Hatzis\n", 78 | "\n", 79 | "GNU Lesser General Public License v3.0\n", 80 | "\n", 81 | "CACHE Connection object to SAMPLES is created successfully.\n", 82 | "CACHE Connection Implementation Version : 1.0.1\n", 83 | "CACHE Database object is created successfully\n", 84 | "CACHE Class object is created successfully\n", 85 | "CACHE Instance object is created successfully\n" 86 | ] 87 | }, 88 | { 89 | "data": { 90 | "text/plain": [ 91 | "CacheClass(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', 'No Object Set')" 92 | ] 93 | }, 94 | "execution_count": 5, 95 | "metadata": {}, 96 | "output_type": "execute_result" 97 | } 98 | ], 99 | "source": [ 100 | "person = CacheClass(username='_SYSTEM', password='SYS', dl=99)\n", 101 | "person" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 6, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "CacheClass(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='SAMPLES', cacheclass='SAMPLES.Sample.Person', 'No Object Set')\n" 114 | ] 115 | } 116 | ], 117 | "source": [ 118 | "print(person)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 7, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "CACHE_Object : \n", 131 | "CACHE_Database : \n", 132 | "CACHE_Connection : \n" 133 | ] 134 | } 135 | ], 136 | "source": [ 137 | "print(person.private_attributes)" 138 | ] 139 | }, 140 | { 141 | "cell_type": "markdown", 142 | "metadata": {}, 143 | "source": [ 144 | "## Create a New CACHE Object on the instance of Cache Class" 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 8, 150 | "metadata": {}, 151 | "outputs": [ 152 | { 153 | "data": { 154 | "text/plain": [ 155 | "CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', 'New Object Set')" 156 | ] 157 | }, 158 | "execution_count": 8, 159 | "metadata": {}, 160 | "output_type": "execute_result" 161 | } 162 | ], 163 | "source": [ 164 | "person.new()" 165 | ] 166 | }, 167 | { 168 | "cell_type": "markdown", 169 | "metadata": {}, 170 | "source": [ 171 | "## Set CACHE Object properties" 172 | ] 173 | }, 174 | { 175 | "cell_type": "code", 176 | "execution_count": 9, 177 | "metadata": { 178 | "collapsed": true 179 | }, 180 | "outputs": [], 181 | "source": [ 182 | "person.set_value(\"SSN\",populateUtils.class_method(\"SSN\"))\n", 183 | "person.set_value(\"Name\", populateUtils.class_method(\"Name\",\"1\"))\n", 184 | "person.set_value(\"DOB\", populateUtils.class_method(\"Date\"))" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 10, 190 | "metadata": {}, 191 | "outputs": [ 192 | { 193 | "name": "stdout", 194 | "output_type": "stream", 195 | "text": [ 196 | "ID:None\n", 197 | "SSN: 499-62-7568\n", 198 | "Name:Vonnegut,Chris E.\n", 199 | "DateOfBirth:1931-05-28\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "print(f\"ID:{person.id}\\nSSN: {person.get('SSN')}\\nName:{person.get('Name')}\\nDateOfBirth:{person.get('DOB')}\")" 205 | ] 206 | }, 207 | { 208 | "cell_type": "markdown", 209 | "metadata": {}, 210 | "source": [ 211 | "## Save CACHE Object" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": 11, 217 | "metadata": {}, 218 | "outputs": [ 219 | { 220 | "data": { 221 | "text/plain": [ 222 | "(CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', '204'),\n", 223 | " status(0,))" 224 | ] 225 | }, 226 | "execution_count": 11, 227 | "metadata": {}, 228 | "output_type": "execute_result" 229 | } 230 | ], 231 | "source": [ 232 | "person.save()" 233 | ] 234 | }, 235 | { 236 | "cell_type": "markdown", 237 | "metadata": {}, 238 | "source": [ 239 | "## Create another CACHE Object" 240 | ] 241 | }, 242 | { 243 | "cell_type": "code", 244 | "execution_count": 12, 245 | "metadata": {}, 246 | "outputs": [ 247 | { 248 | "data": { 249 | "text/plain": [ 250 | "CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', 'New Object Set')" 251 | ] 252 | }, 253 | "execution_count": 12, 254 | "metadata": {}, 255 | "output_type": "execute_result" 256 | } 257 | ], 258 | "source": [ 259 | "female = CacheClass(username='_SYSTEM', password='SYS')\n", 260 | "female.new()" 261 | ] 262 | }, 263 | { 264 | "cell_type": "code", 265 | "execution_count": 13, 266 | "metadata": {}, 267 | "outputs": [ 268 | { 269 | "data": { 270 | "text/plain": [ 271 | "(CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', '205'),\n", 272 | " status(0,))" 273 | ] 274 | }, 275 | "execution_count": 13, 276 | "metadata": {}, 277 | "output_type": "execute_result" 278 | } 279 | ], 280 | "source": [ 281 | "female.set_value(\"SSN\",populateUtils.class_method(\"SSN\"))\n", 282 | "female.set_value(\"Name\", populateUtils.class_method(\"Name\",\"2\"))\n", 283 | "female.set_value(\"DOB\", populateUtils.class_method(\"Date\"))\n", 284 | "female.save()" 285 | ] 286 | }, 287 | { 288 | "cell_type": "code", 289 | "execution_count": 14, 290 | "metadata": {}, 291 | "outputs": [ 292 | { 293 | "name": "stdout", 294 | "output_type": "stream", 295 | "text": [ 296 | "ID:205\n", 297 | "SSN: 957-76-5803\n", 298 | "Name:Long,Lydia H.\n", 299 | "DateOfBirth:1966-07-01\n" 300 | ] 301 | } 302 | ], 303 | "source": [ 304 | "print(f\"ID:{female.id}\\nSSN: {female.get('SSN')}\\nName:{female.get('Name')}\\nDateOfBirth:{female.get('DOB')}\")" 305 | ] 306 | }, 307 | { 308 | "cell_type": "markdown", 309 | "metadata": {}, 310 | "source": [ 311 | "## Set Object References" 312 | ] 313 | }, 314 | { 315 | "cell_type": "code", 316 | "execution_count": 15, 317 | "metadata": {}, 318 | "outputs": [ 319 | { 320 | "data": { 321 | "text/plain": [ 322 | "(CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', '205'),\n", 323 | " status(0,))" 324 | ] 325 | }, 326 | "execution_count": 15, 327 | "metadata": {}, 328 | "output_type": "execute_result" 329 | } 330 | ], 331 | "source": [ 332 | "female.set_refobj(\"Spouse\", person._cache_id)\n", 333 | "female.save()" 334 | ] 335 | }, 336 | { 337 | "cell_type": "code", 338 | "execution_count": 16, 339 | "metadata": {}, 340 | "outputs": [ 341 | { 342 | "data": { 343 | "text/plain": [ 344 | "(CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', '204'),\n", 345 | " status(0,))" 346 | ] 347 | }, 348 | "execution_count": 16, 349 | "metadata": {}, 350 | "output_type": "execute_result" 351 | } 352 | ], 353 | "source": [ 354 | "person.set_refobj(\"Spouse\", female._cache_id)\n", 355 | "person.save()" 356 | ] 357 | }, 358 | { 359 | "cell_type": "markdown", 360 | "metadata": {}, 361 | "source": [ 362 | "## Get Object References" 363 | ] 364 | }, 365 | { 366 | "cell_type": "code", 367 | "execution_count": 17, 368 | "metadata": {}, 369 | "outputs": [ 370 | { 371 | "data": { 372 | "text/plain": [ 373 | "'Long,Lydia H.'" 374 | ] 375 | }, 376 | "execution_count": 17, 377 | "metadata": {}, 378 | "output_type": "execute_result" 379 | } 380 | ], 381 | "source": [ 382 | "person.get(\"Spouse\").get(\"Name\")" 383 | ] 384 | }, 385 | { 386 | "cell_type": "code", 387 | "execution_count": 18, 388 | "metadata": {}, 389 | "outputs": [ 390 | { 391 | "data": { 392 | "text/plain": [ 393 | "'Vonnegut,Chris E.'" 394 | ] 395 | }, 396 | "execution_count": 18, 397 | "metadata": {}, 398 | "output_type": "execute_result" 399 | } 400 | ], 401 | "source": [ 402 | "female.get(\"Spouse\").get(\"Name\")" 403 | ] 404 | }, 405 | { 406 | "cell_type": "markdown", 407 | "metadata": {}, 408 | "source": [ 409 | "## Create a CACHE Embedded Object " 410 | ] 411 | }, 412 | { 413 | "cell_type": "code", 414 | "execution_count": 19, 415 | "metadata": { 416 | "collapsed": true 417 | }, 418 | "outputs": [], 419 | "source": [ 420 | "street = populateUtils.class_method(\"Street\")\n", 421 | "city = populateUtils.class_method(\"City\")\n", 422 | "state = populateUtils.class_method(\"USState\")\n", 423 | "uszip = populateUtils.class_method(\"USZip\")" 424 | ] 425 | }, 426 | { 427 | "cell_type": "code", 428 | "execution_count": 20, 429 | "metadata": { 430 | "collapsed": true 431 | }, 432 | "outputs": [], 433 | "source": [ 434 | "home_address = female.set_embobj('Sample.Address', 'Home')\n", 435 | "home_address.set(\"Street\",street)\n", 436 | "home_address.set(\"City\",city)\n", 437 | "home_address.set(\"State\",state)\n", 438 | "home_address.set(\"Zip\",uszip)" 439 | ] 440 | }, 441 | { 442 | "cell_type": "code", 443 | "execution_count": 21, 444 | "metadata": {}, 445 | "outputs": [ 446 | { 447 | "data": { 448 | "text/plain": [ 449 | "(CacheClass Object(localhost, 1972, _SYSTEM, SYS, SAMPLES, 'SAMPLES.Sample.Person', '205'),\n", 450 | " status(0,))" 451 | ] 452 | }, 453 | "execution_count": 21, 454 | "metadata": {}, 455 | "output_type": "execute_result" 456 | } 457 | ], 458 | "source": [ 459 | "female.save()" 460 | ] 461 | }, 462 | { 463 | "cell_type": "code", 464 | "execution_count": 22, 465 | "metadata": {}, 466 | "outputs": [ 467 | { 468 | "data": { 469 | "text/plain": [ 470 | "['3152 Madison Court', 'Islip', 'GA', '99159']" 471 | ] 472 | }, 473 | "execution_count": 22, 474 | "metadata": {}, 475 | "output_type": "execute_result" 476 | } 477 | ], 478 | "source": [ 479 | "[female.get('Home').get(property) for property in ['Street', 'City', 'State', 'Zip']]" 480 | ] 481 | }, 482 | { 483 | "cell_type": "code", 484 | "execution_count": null, 485 | "metadata": { 486 | "collapsed": true 487 | }, 488 | "outputs": [], 489 | "source": [] 490 | } 491 | ], 492 | "metadata": { 493 | "kernelspec": { 494 | "display_name": "Python 3", 495 | "language": "python", 496 | "name": "python3" 497 | }, 498 | "language_info": { 499 | "codemirror_mode": { 500 | "name": "ipython", 501 | "version": 3 502 | }, 503 | "file_extension": ".py", 504 | "mimetype": "text/x-python", 505 | "name": "python", 506 | "nbconvert_exporter": "python", 507 | "pygments_lexer": "ipython3", 508 | "version": "3.6.3" 509 | } 510 | }, 511 | "nbformat": 4, 512 | "nbformat_minor": 2 513 | } 514 | -------------------------------------------------------------------------------- /cacheorm.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import pandas as pd 3 | 4 | from intersys import pythonbind3 5 | 6 | ## ********************************************************************************* 7 | # ******************************** Module Function Definitions ********************* 8 | 9 | def print_exception(err): 10 | print() 11 | print(' ********** InterSystems Cache exception ********** ') 12 | print('Exception Type : ',sys.exc_info()[0]) 13 | print('Exception Value : ',sys.exc_info()[1]) 14 | print('Exception Traceback : ',sys.exc_info()[2]) 15 | print(' ************************************************** ') 16 | print('Exception Error : ',str(err)) 17 | 18 | # ***************************************************************************** 19 | # ******************************** Classes Specifications ********************* 20 | # ***************************************************************************** 21 | 22 | class CacheClient(object): 23 | """ 24 | This is the super class of CachePython module. 25 | It wraps two functions from intersys.pythonbind module 26 | pythonbind3.connection() and pythonbind3.database(). 27 | """ 28 | def __init__(self, host='localhost', port=1972, 29 | username='_SYSTEM', password='SYS', 30 | namespace='SAMPLES', dl=0): 31 | 32 | """ 33 | CacheClient.__init__ 34 | ---------------------- 35 | Initialization of a CacheClient object 36 | 37 | 38 | Optional Keyword Arguments 39 | --------------------------- 40 | host : string -- (default = 'localhost') 41 | Intersystems Cache database server 42 | 43 | port : integer -- (default = 1972) 44 | Intersystems Cache Server TCP/IP port that is used to accept incoming client requests 45 | 46 | username : string -- (default = '_SYSTEM') 47 | Intersystems Cache username 48 | 49 | password : string -- (default = 'SYS') 50 | Intersystems Cache authentication method with password 51 | 52 | namespace : string -- (default = 'SAMPLES') 53 | Intersystems Cache Namespace containing the objects to be used. 54 | This namespace must have the Caché system classes compiled, 55 | and must contain the objects you want to manipulate 56 | 57 | debug : boolean -- (default = False) 58 | print messages for debugging purposes 59 | 60 | Private Instance Attributes 61 | --------------------------- 62 | _connection : Intersystems Cache Connection instance (intersys.pythonbind.connection) 63 | 64 | _database : Intersystems Cache Database instance (intersys.pythonbind.database) 65 | 66 | """ 67 | 68 | self.cache_host = host 69 | self.cache_port = port 70 | self.cache_username = username 71 | self.cache_password = password 72 | self.cache_namespace = namespace 73 | self.debug_level = dl 74 | 75 | # Debug messages 76 | if self.debug_level==99: 77 | print('Cache Python Object-Relational Mapper Module : ') 78 | print('Enhanced OOP porting of Intersystems Cache python binding modules') 79 | print('(C) 2017-2018 HEALIS.EU - Athanassios I. Hatzis\n') 80 | print('GNU Lesser General Public License v3.0\n') 81 | 82 | # try to create intersys.pythonbind.connection object 83 | try: 84 | self._connection = pythonbind3.connection() 85 | 86 | url = self.cache_host+'['+str(self.cache_port)+']:'+self.cache_namespace 87 | self._connection.connect_now(url, self.cache_username, self.cache_password, None) 88 | if self.debug_level>1: 89 | print('CACHE Connection object to ', self.cache_namespace, ' is created successfully.') 90 | 91 | self.connection_version = self._connection.get_implementation_version() 92 | if self.debug_level>1: 93 | print('CACHE Connection Implementation Version : ',self.connection_version) 94 | 95 | except pythonbind3.cache_exception as err: 96 | print_exception(err) 97 | 98 | # try to create intersys.pythonbind.database object 99 | try: 100 | self._database = pythonbind3.database(self._connection) 101 | if self.debug_level>1: 102 | print('CACHE Database object is created successfully') 103 | 104 | except pythonbind3.database_exception as err: 105 | print_exception(err) 106 | 107 | def __repr__(self): 108 | return f"{self.cache_host}, {self.cache_port}, {self.cache_username}, {self.cache_password}, {self.cache_namespace}" 109 | 110 | 111 | def __str__(self): 112 | return f"host='{self.cache_host}', port={self.cache_port}, username='{self.cache_username}', password='{self.cache_password}', namespace='{self.cache_namespace}'" 113 | 114 | @property 115 | def private_attributes(self): 116 | type1 = type(self._database) 117 | type2 = type(self._connection) 118 | return f'CACHE_Database : {type1} \nCACHE_Connection : {type2}' 119 | 120 | 121 | # ********************************************************************************* 122 | # ************************** End of CacheClient *********************************** 123 | # ********************************************************************************* 124 | 125 | class CacheQuery(CacheClient): 126 | ''' 127 | A subclass of CacheClient that wraps methods of the intersys.pythonbind.database 128 | class and intersys.pythonbind.query class. Provides enhanced usage of Cache Queries. 129 | ''' 130 | 131 | def __init__(self, cachepackage='Sample', cacheclass = 'Person', **kwargs): 132 | """ 133 | CacheQuery.__init__ 134 | -------------------------------- 135 | CacheQuery initialization method 136 | 137 | 138 | Private Instance Attributes 139 | -------------------------- 140 | _query : Intersystems Cache query object (intersys.pythonbind.query) 141 | 142 | 143 | Examples 144 | ---------- 145 | >>> samples_query = CacheQuery(namespace = "SAMPLES") 146 | >>> samples_query = CacheQuery(username='athanassios', password='123', namespace='SAMPLES') 147 | """ 148 | 149 | # invoke CacheClient __init__ method 150 | super().__init__(**kwargs) 151 | self.cache_package = cachepackage 152 | self.cache_classname = cacheclass 153 | self.cache_classname_package = self.cache_package + '.' + self.cache_classname 154 | self.cache_classname_full = self.cache_namespace + '.' + self.cache_package + '.' + self.cache_classname 155 | 156 | try: 157 | # create intersys.pythonbind.query object 158 | self._query = pythonbind3.query(self._database) 159 | 160 | if self.debug_level>1: 161 | print('CACHE Query object created successfully') 162 | 163 | self.total_records=0 # total number of records in the result set 164 | self.counter = 0 # count records fetched from result_set 165 | self.record_set = None # Pandas DataFrame to display result_set 166 | except pythonbind3.cache_exception as err: 167 | print_exception(err) 168 | 169 | 170 | def __repr__(self): 171 | return "CacheQuery(" + super().__repr__() + f", {self.cache_package}, {self.cache_classname})" 172 | 173 | 174 | def __str__(self): 175 | return "CacheQuery(" + super().__str__() + f", cachepackage='{self.cache_package}', cacheclass='{self.cache_classname}')" 176 | 177 | 178 | @property 179 | def private_attributes(self): 180 | return f'CACHE_Query : {type(self._query)} \n' + super().private_attributes 181 | 182 | 183 | @property 184 | def result_set(self): 185 | """ 186 | This is a generator based on the result set 187 | that is fetched through the cache_query attribute 188 | 189 | Returns 190 | --------- 191 | returns records from the result set, one record at a time 192 | 193 | """ 194 | while True: 195 | single_record = self._query.fetch([None]) 196 | # If the list of single_record is empty break else yield the record 197 | if not single_record: 198 | break 199 | else: 200 | yield single_record 201 | 202 | 203 | # result set columns - getter method 204 | @property 205 | def columns(self): 206 | """ 207 | get the column header of the result set 208 | 209 | Returns 210 | --------- 211 | A python list of names for each of the columns in the query result set 212 | 213 | Examples 214 | ---------- 215 | >>> samples_query.columns 216 | """ 217 | return [self._query.col_name(idx) for idx in range(1,self._query.num_cols()+1)] 218 | 219 | 220 | # columns types - getter method 221 | @property 222 | def columns_types(self): 223 | """ 224 | get the sql types for each column in the header of the result set 225 | 226 | Returns 227 | --------- 228 | A python list of sql types for each of the columns in the query result set 229 | 230 | Examples 231 | ---------- 232 | >>> samples_query.columns_types 233 | """ 234 | 235 | return [self._query.col_sql_type(idx) for idx in range(1,self._query.num_cols()+1)] 236 | 237 | def execute(self): 238 | self._query.execute() # execute generates the record result set 239 | self.counter = 0 # reset the counter 240 | if self.debug_level>1 : 241 | print('result set is now ready and can be fetched') 242 | 243 | def execute_call(self, clname, procname, *params): 244 | """ 245 | prepares and executes an SQL procedure call. 246 | This is usually a class method or class query 247 | that is exposed as an SQL stored procedure 248 | 249 | Notice 250 | ------ 251 | you can invoke SQL stored procedure with the CALL statement 252 | by passing an sql string to execute_sql 253 | 254 | 255 | Keyword argument 256 | ---------------- 257 | class_name : string 258 | name of Cache class that is defined in the current namespace.package 259 | proc_name : string 260 | either the name of a class method or class query 261 | 262 | 263 | Examples 264 | ---------- 265 | >>> samples_query.execute_call('Person', 'Extent') 266 | >>> samples_query.execute_call('Person', 'ByName', 'A') 267 | """ 268 | clname=self.cache_package+'.'+clname 269 | self._query.prepare_class(clname, procname) 270 | idx = 0 271 | for par in params: 272 | idx = idx+1 273 | self._query.set_par(idx, par) 274 | self.execute() 275 | 276 | def execute_sql(self, sql, *params): 277 | """ 278 | prepares and executes an SQL query 279 | 280 | Notice 281 | --------------- 282 | the result set is fetched from the result_set generator 283 | 284 | Keyword arguments 285 | ---------------- 286 | sql : string 287 | SQL commands to be executed 288 | 289 | Examples 290 | ---------- 291 | >>> samples_query.execute_query_sql('SELECT ID, Name, DOB, SSN FROM Sample.Person') 292 | >>> samples_query.execute_query_sql('CALL HYPEDB.Node_ViewUnionByType') 293 | """ 294 | self._query.prepare(sql) 295 | idx = 0 296 | for par in params: 297 | idx = idx+1 298 | self._query.set_par(idx, par) 299 | self.execute() 300 | 301 | # total number of records in the result set 302 | def count_records(self): 303 | self.total_records=0 304 | while True: 305 | try: 306 | next(self.result_set) 307 | self.counter=self.counter+1 308 | self.total_records=self.total_records+1 309 | except StopIteration: 310 | return self.total_records 311 | break 312 | 313 | def display_records(self, iterations=10, maxrows=False, maxwidth=180): 314 | # Set display width for PANDAS Data Frame 315 | pd.set_option('display.width', maxwidth) 316 | 317 | # Check whether to display ALL rows of the PANDAS Data Frame or NOT 318 | if maxrows and self.total_records>0: 319 | pd.set_option('display.max_rows',self.total_records) 320 | else: 321 | pd.reset_option('display.max_rows') 322 | 323 | # Fill Pandas Data Frame with a number of records that are fetched from the query result set 324 | self.record_set = pd.DataFrame(columns = self.columns) 325 | for i in range(iterations): 326 | try: 327 | elem = next(self.result_set) 328 | self.record_set.loc[i]=elem 329 | self.counter=self.counter+1 330 | except StopIteration: 331 | print("Execution reached the end of the result set") 332 | return self.record_set 333 | break 334 | return self.record_set 335 | 336 | def print_records(self, iterations=10): 337 | for i in range(iterations): 338 | try: 339 | elem = next(self.result_set) 340 | self.counter=self.counter+1 341 | print(f"Iter: {i}, Cnt: {self.counter} - Element: {elem}") 342 | except (StopIteration, pythonbind3.cache_exception) as err: 343 | print_exception(err) 344 | print("Execution reached the end of the result set") 345 | break 346 | 347 | def skip_records(self, iternum=1): 348 | for i in range(iternum): 349 | try: 350 | next(self.result_set) 351 | self.counter=self.counter+1 352 | except StopIteration: 353 | print("Execution reached the end of the result set") 354 | break 355 | 356 | # ************************************************************************************ 357 | # ************************ End of CacheQuery Class ************************************ 358 | # ************************************************************************************* 359 | 360 | class CacheClass(CacheClient): 361 | ''' 362 | A subclass of CacheClient, that wraps methods of 363 | the intersys.pythonbind.Database class and the intersys.pythonbind.object class 364 | ''' 365 | 366 | def __init__(self, cachepackage='Sample', cacheclass='Person', objectID=None, **kwargs): 367 | """ 368 | CacheClass.__init__ 369 | -------------------- 370 | CacheClass initialization method 371 | 372 | 373 | Keyword argument 374 | ---------------- 375 | cachepackage : string -- (default = Sample) 376 | cacheclass : string -- (default = Person) 377 | objectID : string -- (default = None) 378 | An object identifier. 379 | A value that uniquely identifies a specific instance within a particular Cache extent 380 | The ID refers to an on-disk version of an object. 381 | It does not include any class-specific information. 382 | 383 | 384 | Private Instance Attributes 385 | -------------------------- 386 | _instance : Intersystems Cache object (intersys.pythonbind.object) 387 | it is set with a call to either cache_database.create_new() or cache_database.openid( 388 | 389 | 390 | 391 | Examples 392 | ---------- 393 | >>> personClass = CacheClass(cacheclass='Employee') 394 | >>> person = CacheClass(namespace = 'SAMPLES', cacheclass='Sample.Person', objectID='1') 395 | >>> person = CacheInstance() 396 | """ 397 | 398 | # invoke CacheClient __init__ method 399 | super().__init__(**kwargs) 400 | self.cache_package = cachepackage 401 | self.cache_classname = cacheclass 402 | self.cache_classname_package = self.cache_package + '.' + self.cache_classname 403 | self.cache_classname_full = self.cache_namespace + '.' + self.cache_package + '.' + self.cache_classname 404 | self._cache_id = objectID 405 | 406 | # set an instance of intersys.pythonbind.object 407 | if objectID: 408 | # open an instance of intersys.pythonbind.database object with ID 409 | self._instance, self._cache_id = self.open_id(objectID) 410 | else: 411 | self._instance=None 412 | 413 | if self.debug_level>1: 414 | print('CACHE Class object is created successfully') 415 | print('CACHE Instance object is created successfully') 416 | 417 | # There are three cases 418 | def __repr__(self): 419 | 420 | # a) Instance of the CacheClass no CACHE Object is created and no CACHE Object is open 421 | if self._instance is None: 422 | return "CacheClass(" + CacheClient.__repr__(self) + f", '{self.cache_classname_full}', 'No Object Set')" 423 | 424 | # b) Instance of the CacheClass with a new CACHE Object created 425 | elif (self._instance is not None) and (self._cache_id is None): 426 | return "CacheClass Object(" + CacheClient.__repr__(self) + f", '{self.cache_classname_full}', 'New Object Set')" 427 | 428 | # c) Instance of the CacheClass with a CACHE Object that exists in the database 429 | elif self._cache_id is not None: 430 | return "CacheClass Object(" + CacheClient.__repr__(self) + f", '{self.cache_classname_full}', '{self._cache_id}')" 431 | 432 | # There are three cases 433 | def __str__(self): 434 | # a) Instance of the CacheClass no CACHE Object is created and no CACHE Object is open 435 | if self._instance is None: 436 | return "CacheClass(" + CacheClient.__str__(self) + f", cacheclass='{self.cache_classname_full}', 'No Object Set')" 437 | 438 | # b) Instance of the CacheClass with a new CACHE Object created 439 | elif (self._instance is not None) and (self._cache_id is None): 440 | return "CacheClass(" + CacheClient.__str__(self) + f", cacheclass='{self.cache_classname_full}', 'New Object Set')" 441 | 442 | # c) Instance of the CacheClass with a CACHE Object that exists in the database 443 | elif self._cache_id is not None: 444 | return "CacheClass(" + CacheClient.__str__(self) + f", cacheclass='{self.cache_classname_full}', objectID='{self._cache_id}')" 445 | 446 | 447 | @property 448 | def private_attributes(self): 449 | return f'CACHE_Object : {type(self._instance)} \n' + super().private_attributes 450 | 451 | 452 | @property 453 | def id(self): 454 | if not self._cache_id: 455 | return None 456 | else: 457 | return self.object_method('%Id') 458 | 459 | @property 460 | def cache_objref(self): 461 | return self._instance 462 | 463 | 464 | @property 465 | def description(self): 466 | return self._instance.get_obj_desc() 467 | 468 | # ************************************************************************ 469 | # ======= METHODS SECTION ======= 470 | 471 | def class_method(self, method_name, *kargs): 472 | try: 473 | return self._database.run_class_method(self.cache_classname_package, method_name, list(kargs)) 474 | except pythonbind3.cache_exception as err: 475 | print_exception(err) 476 | 477 | # Create a new object in CACHE _database that is already connected in the instance of CacheClass 478 | # Attention: We do not open another connection here to create the object 479 | def new(self): 480 | self._cache_id=None 481 | # create a new instance of intersys.pythonbind.database object 482 | self._instance = self._database.create_new(self.cache_classname_package, None) 483 | return self 484 | 485 | 486 | def save(self): 487 | if self._instance is None: 488 | raise RuntimeError("No Object has been created or opened in the database") 489 | else: 490 | result = self.object_method("%Save") 491 | self._cache_id = self.object_method("%Id") 492 | 493 | return self, result 494 | 495 | 496 | def open_id(self, object_id): 497 | # check if there is a record with this ID in the class 498 | if not self.exists_id(object_id): 499 | message = "Record with objectID " + object_id + " does not exist in " + self.cache_classname_full 500 | raise ValueError(message) 501 | else: 502 | intersysobj = self._database.openid(self.cache_classname_package, object_id, -1, -1) 503 | return intersysobj, object_id 504 | 505 | 506 | def get(self, prop_name): 507 | if self._instance is None: 508 | raise RuntimeError("No Object has been created or opened in the database") 509 | else: 510 | return self._instance.get(prop_name) 511 | 512 | 513 | def set_value(self, prop_name, value): 514 | if self._instance is None: 515 | raise RuntimeError("No Object has been created or opened in the database") 516 | else: 517 | self._instance.set(prop_name, value) 518 | 519 | 520 | def set_embobj(self, classname, propname, **kwargs): 521 | # we create a new intersys.pythonbind3.object 522 | # because an attempt to pass a reference with the set_value() 523 | # results to the same cache ID (see testCacheInstance2) 524 | # and an attempt to save it result in circular reference 525 | intersysobj = self._database.create_new(classname, None) 526 | self._instance.set(propname, intersysobj) 527 | return intersysobj 528 | 529 | 530 | def set_refobj(self, prop_name, cacheid): 531 | # we create a new intersys.pythonbind3.object 532 | # because an attempt to pass a reference with the set_value() 533 | # results to the same cache ID (see testCacheInstance2) 534 | # 535 | # check if there is a record with this ID in the class 536 | if not self.exists_id(cacheid): 537 | message = "Record with objectID " + cacheid + " does not exist in " + self.cache_classname_full 538 | raise ValueError(message) 539 | else: 540 | intersysobj = self._database.openid(self.cache_classname_package, cacheid, -1, -1) 541 | self._instance.set(prop_name, intersysobj) 542 | return intersysobj 543 | 544 | 545 | def exists_id(self, object_id): 546 | result = self.class_method('%ExistsId', object_id) 547 | if result==1: 548 | return True 549 | elif result==0: 550 | return False 551 | 552 | 553 | def delete_id(self, object_id): 554 | if self.exists_id(object_id): 555 | result = self.class_method('%DeleteId', object_id) 556 | else: 557 | result = False 558 | return result 559 | 560 | 561 | def object_method(self, method_name, *kargs): 562 | try: 563 | return self._instance.run_obj_method(method_name, list(kargs)) 564 | except pythonbind3.cache_exception as err: 565 | print_exception(err) 566 | 567 | # ********************************************************************************* 568 | # ************************** End of CacheClass *********************************** 569 | # ********************************************************************************* 570 | -------------------------------------------------------------------------------- /testCacheORM/testCacheORM - Cache Queries.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Demo of CacheORM Module - Cache Queries" 8 | ] 9 | }, 10 | { 11 | "cell_type": "code", 12 | "execution_count": 1, 13 | "metadata": {}, 14 | "outputs": [], 15 | "source": [ 16 | "from CacheORM import CacheQuery" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "## Create a CacheInstance object" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 2, 29 | "metadata": {}, 30 | "outputs": [ 31 | { 32 | "name": "stdout", 33 | "output_type": "stream", 34 | "text": [ 35 | "Cache Python Object-Relational Mapper Module : \n", 36 | "Enhanced OOP porting of Intersystems Cache python binding modules\n", 37 | "(C) 2017-2018 HEALIS.EU - Athanassios I. Hatzis\n", 38 | "\n", 39 | "GNU Lesser General Public License v3.0\n", 40 | "\n", 41 | "CACHE Connection object to SAMPLES is created successfully.\n", 42 | "CACHE Connection Implementation Version : 1.0.1\n", 43 | "CACHE Database object is created successfully\n", 44 | "CACHE Query object created successfully\n" 45 | ] 46 | }, 47 | { 48 | "data": { 49 | "text/plain": [ 50 | "CacheQuery(localhost, 1972, _SYSTEM, SYS, SAMPLES, Sample, Person)" 51 | ] 52 | }, 53 | "execution_count": 2, 54 | "metadata": {}, 55 | "output_type": "execute_result" 56 | } 57 | ], 58 | "source": [ 59 | "samples_query = CacheQuery(namespace='SAMPLES', username='_SYSTEM', password='SYS', dl=99)\n", 60 | "samples_query" 61 | ] 62 | }, 63 | { 64 | "cell_type": "code", 65 | "execution_count": 3, 66 | "metadata": {}, 67 | "outputs": [ 68 | { 69 | "name": "stdout", 70 | "output_type": "stream", 71 | "text": [ 72 | "CacheQuery(host='localhost', port=1972, username='_SYSTEM', password='SYS', namespace='SAMPLES', cachepackage='Sample', cacheclass='Person')\n" 73 | ] 74 | } 75 | ], 76 | "source": [ 77 | "print(samples_query)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 4, 83 | "metadata": {}, 84 | "outputs": [ 85 | { 86 | "name": "stdout", 87 | "output_type": "stream", 88 | "text": [ 89 | "CACHE_Query : \n", 90 | "CACHE_Database : \n", 91 | "CACHE_Connection : \n" 92 | ] 93 | } 94 | ], 95 | "source": [ 96 | "print(samples_query.private_attributes)" 97 | ] 98 | }, 99 | { 100 | "cell_type": "markdown", 101 | "metadata": {}, 102 | "source": [ 103 | "## Execute SQL query by passing an SQL string" 104 | ] 105 | }, 106 | { 107 | "cell_type": "code", 108 | "execution_count": 5, 109 | "metadata": {}, 110 | "outputs": [ 111 | { 112 | "name": "stdout", 113 | "output_type": "stream", 114 | "text": [ 115 | "result set is now ready and can be fetched\n" 116 | ] 117 | } 118 | ], 119 | "source": [ 120 | "samples_query.execute_sql('SELECT ID, Name, DOB, SSN FROM Sample.Person')" 121 | ] 122 | }, 123 | { 124 | "cell_type": "markdown", 125 | "metadata": {}, 126 | "source": [ 127 | "### get the header of the result set" 128 | ] 129 | }, 130 | { 131 | "cell_type": "code", 132 | "execution_count": 6, 133 | "metadata": {}, 134 | "outputs": [ 135 | { 136 | "data": { 137 | "text/plain": [ 138 | "['ID', 'Name', 'DOB', 'SSN']" 139 | ] 140 | }, 141 | "execution_count": 6, 142 | "metadata": {}, 143 | "output_type": "execute_result" 144 | } 145 | ], 146 | "source": [ 147 | "samples_query.columns" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "### query result set is a generator object" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 7, 160 | "metadata": {}, 161 | "outputs": [ 162 | { 163 | "data": { 164 | "text/plain": [ 165 | "" 166 | ] 167 | }, 168 | "execution_count": 7, 169 | "metadata": {}, 170 | "output_type": "execute_result" 171 | } 172 | ], 173 | "source": [ 174 | "samples_query.result_set" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": {}, 180 | "source": [ 181 | "### count the total number of records in the result set" 182 | ] 183 | }, 184 | { 185 | "cell_type": "code", 186 | "execution_count": 8, 187 | "metadata": {}, 188 | "outputs": [ 189 | { 190 | "data": { 191 | "text/plain": [ 192 | "203" 193 | ] 194 | }, 195 | "execution_count": 8, 196 | "metadata": {}, 197 | "output_type": "execute_result" 198 | } 199 | ], 200 | "source": [ 201 | "samples_query.count_records()" 202 | ] 203 | }, 204 | { 205 | "cell_type": "markdown", 206 | "metadata": {}, 207 | "source": [ 208 | "### re-execute query" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 9, 214 | "metadata": {}, 215 | "outputs": [ 216 | { 217 | "name": "stdout", 218 | "output_type": "stream", 219 | "text": [ 220 | "result set is now ready and can be fetched\n" 221 | ] 222 | } 223 | ], 224 | "source": [ 225 | "samples_query.execute_sql('SELECT ID, Name, DOB, SSN FROM Sample.Person')" 226 | ] 227 | }, 228 | { 229 | "cell_type": "markdown", 230 | "metadata": {}, 231 | "source": [ 232 | "### print records" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 10, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "Iter: 0, Cnt: 1 - Element: [1, 'Isaksen,Alexandra T.', 1957-12-12, '207-26-6677']\n", 245 | "Iter: 1, Cnt: 2 - Element: [2, 'Isaacs,Emily R.', 1930-10-31, '295-77-6690']\n", 246 | "Iter: 2, Cnt: 3 - Element: [3, 'Feynman,James K.', 1968-07-21, '928-52-1962']\n", 247 | "Iter: 3, Cnt: 4 - Element: [4, 'Vanzetti,Mary R.', 2014-06-14, '234-96-2703']\n", 248 | "Iter: 4, Cnt: 5 - Element: [5, 'Orwell,Alfred R.', 1986-04-13, '422-27-1069']\n", 249 | "Iter: 5, Cnt: 6 - Element: [6, 'Ironhorse,Stuart F.', 1930-05-27, '597-44-6996']\n", 250 | "Iter: 6, Cnt: 7 - Element: [7, 'Browning,Mary C.', 1927-04-25, '692-44-7227']\n", 251 | "Iter: 7, Cnt: 8 - Element: [8, 'Jones,David S.', 1965-02-11, '269-67-6145']\n", 252 | "Iter: 8, Cnt: 9 - Element: [9, 'Xavier,Dan K.', 1949-06-29, '335-82-9284']\n", 253 | "Iter: 9, Cnt: 10 - Element: [10, 'Goncharuk,Greta W.', 1966-06-02, '134-52-9380']\n", 254 | "Iter: 10, Cnt: 11 - Element: [11, 'Yang,Angela V.', 1983-09-24, '913-73-2957']\n", 255 | "Iter: 11, Cnt: 12 - Element: [12, 'Palmer,Jules O.', 1988-05-30, '372-68-7006']\n", 256 | "Iter: 12, Cnt: 13 - Element: [13, 'Vonnegut,Danielle U.', 1947-07-26, '437-26-4645']\n", 257 | "Iter: 13, Cnt: 14 - Element: [14, \"O'Brien,Linda Y.\", 1995-11-21, '147-87-7303']\n", 258 | "Iter: 14, Cnt: 15 - Element: [15, 'Vanzetti,Sally C.', 1985-08-27, '232-39-2188']\n", 259 | "Iter: 15, Cnt: 16 - Element: [16, 'Wells,Wolfgang H.', 2004-12-30, '504-94-2516']\n", 260 | "Iter: 16, Cnt: 17 - Element: [17, 'Underman,Angela S.', 2016-06-16, '699-25-7087']\n", 261 | "Iter: 17, Cnt: 18 - Element: [18, 'Tweed,Alvin A.', 1964-07-16, '657-51-8721']\n", 262 | "Iter: 18, Cnt: 19 - Element: [19, 'Clay,Joe N.', 1988-05-18, '609-96-5473']\n", 263 | "Iter: 19, Cnt: 20 - Element: [20, 'Ragon,Valery O.', 1970-10-13, '527-28-3379']\n", 264 | "Iter: 20, Cnt: 21 - Element: [21, 'Munt,Peter N.', 2014-09-15, '590-44-1966']\n", 265 | "Iter: 21, Cnt: 22 - Element: [22, 'Long,Amanda M.', 1930-12-24, '875-21-6177']\n", 266 | "Iter: 22, Cnt: 23 - Element: [23, 'Klausner,Charles U.', 1952-04-03, '648-59-2250']\n", 267 | "Iter: 23, Cnt: 24 - Element: [24, 'Zemaitis,Howard L.', 1956-01-21, '781-50-2402']\n", 268 | "Iter: 24, Cnt: 25 - Element: [25, 'Schulte,Peter L.', 1929-06-19, '188-31-3016']\n", 269 | "Iter: 25, Cnt: 26 - Element: [26, 'Vonnegut,Jose G.', 1980-01-05, '282-12-9112']\n", 270 | "Iter: 26, Cnt: 27 - Element: [27, 'Chadbourne,Alfred O.', 1945-10-02, '222-42-3170']\n", 271 | "Iter: 27, Cnt: 28 - Element: [28, 'Levinson,Zoe O.', 1992-08-03, '864-94-2172']\n", 272 | "Iter: 28, Cnt: 29 - Element: [29, 'Bush,Uma S.', 2005-05-01, '302-57-9782']\n", 273 | "Iter: 29, Cnt: 30 - Element: [30, 'Clinton,Pat P.', 1927-06-02, '624-69-2315']\n", 274 | "Iter: 30, Cnt: 31 - Element: [31, 'Feynman,Dick K.', 1957-09-10, '328-54-8658']\n", 275 | "Iter: 31, Cnt: 32 - Element: [32, 'Xavier,Janice G.', 2000-03-20, '525-76-8476']\n", 276 | "Iter: 32, Cnt: 33 - Element: [33, 'Cerri,Sally E.', 1978-12-24, '633-17-6400']\n", 277 | "Iter: 33, Cnt: 34 - Element: [34, 'Johnson,Chris U.', 1947-06-23, '503-60-3800']\n", 278 | "Iter: 34, Cnt: 35 - Element: [35, 'Eastman,Frances U.', 1961-04-05, '155-60-2820']\n", 279 | "Iter: 35, Cnt: 36 - Element: [36, 'Yezek,Rhonda J.', 1948-06-17, '578-26-1788']\n", 280 | "Iter: 36, Cnt: 37 - Element: [37, 'Tsatsulin,Dan R.', 1974-12-17, '768-70-1581']\n", 281 | "Iter: 37, Cnt: 38 - Element: [38, 'Orlin,Rhonda M.', 1925-07-23, '482-36-6223']\n", 282 | "Iter: 38, Cnt: 39 - Element: [39, 'Newton,Barbara M.', 1974-01-21, '581-24-3221']\n", 283 | "Iter: 39, Cnt: 40 - Element: [40, 'Hertz,Gertrude N.', 1960-01-29, '741-59-7518']\n" 284 | ] 285 | } 286 | ], 287 | "source": [ 288 | "samples_query.print_records(40)" 289 | ] 290 | }, 291 | { 292 | "cell_type": "markdown", 293 | "metadata": {}, 294 | "source": [ 295 | "### display records in a pandas dataframe" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": 11, 301 | "metadata": {}, 302 | "outputs": [ 303 | { 304 | "data": { 305 | "text/html": [ 306 | "
\n", 307 | "\n", 320 | "\n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | " \n", 338 | " \n", 339 | " \n", 340 | " \n", 341 | " \n", 342 | " \n", 343 | " \n", 344 | " \n", 345 | " \n", 346 | " \n", 347 | " \n", 348 | " \n", 349 | " \n", 350 | " \n", 351 | " \n", 352 | " \n", 353 | " \n", 354 | " \n", 355 | " \n", 356 | " \n", 357 | " \n", 358 | " \n", 359 | " \n", 360 | " \n", 361 | " \n", 362 | " \n", 363 | " \n", 364 | " \n", 365 | " \n", 366 | " \n", 367 | " \n", 368 | " \n", 369 | " \n", 370 | " \n", 371 | " \n", 372 | " \n", 373 | " \n", 374 | " \n", 375 | " \n", 376 | " \n", 377 | " \n", 378 | " \n", 379 | " \n", 380 | " \n", 381 | " \n", 382 | " \n", 383 | " \n", 384 | " \n", 385 | " \n", 386 | " \n", 387 | " \n", 388 | " \n", 389 | " \n", 390 | " \n", 391 | " \n", 392 | " \n", 393 | " \n", 394 | " \n", 395 | " \n", 396 | " \n", 397 | " \n", 398 | " \n", 399 | " \n", 400 | " \n", 401 | " \n", 402 | " \n", 403 | " \n", 404 | " \n", 405 | " \n", 406 | " \n", 407 | " \n", 408 | " \n", 409 | " \n", 410 | " \n", 411 | " \n", 412 | " \n", 413 | " \n", 414 | " \n", 415 | " \n", 416 | " \n", 417 | " \n", 418 | " \n", 419 | " \n", 420 | " \n", 421 | " \n", 422 | " \n", 423 | " \n", 424 | " \n", 425 | " \n", 426 | " \n", 427 | " \n", 428 | " \n", 429 | " \n", 430 | " \n", 431 | " \n", 432 | " \n", 433 | " \n", 434 | " \n", 435 | " \n", 436 | " \n", 437 | " \n", 438 | " \n", 439 | " \n", 440 | " \n", 441 | " \n", 442 | " \n", 443 | " \n", 444 | " \n", 445 | " \n", 446 | " \n", 447 | " \n", 448 | " \n", 449 | " \n", 450 | " \n", 451 | " \n", 452 | " \n", 453 | " \n", 454 | " \n", 455 | " \n", 456 | " \n", 457 | " \n", 458 | " \n", 459 | " \n", 460 | " \n", 461 | " \n", 462 | " \n", 463 | " \n", 464 | " \n", 465 | " \n", 466 | " \n", 467 | " \n", 468 | " \n", 469 | " \n", 470 | " \n", 471 | " \n", 472 | " \n", 473 | " \n", 474 | " \n", 475 | " \n", 476 | " \n", 477 | " \n", 478 | " \n", 479 | " \n", 480 | " \n", 481 | " \n", 482 | " \n", 483 | " \n", 484 | " \n", 485 | " \n", 486 | " \n", 487 | " \n", 488 | " \n", 489 | " \n", 490 | " \n", 491 | " \n", 492 | " \n", 493 | " \n", 494 | " \n", 495 | " \n", 496 | " \n", 497 | " \n", 498 | " \n", 499 | " \n", 500 | " \n", 501 | " \n", 502 | " \n", 503 | " \n", 504 | " \n", 505 | " \n", 506 | " \n", 507 | " \n", 508 | " \n", 509 | " \n", 510 | " \n", 511 | " \n", 512 | " \n", 513 | " \n", 514 | " \n", 515 | " \n", 516 | " \n", 517 | " \n", 518 | " \n", 519 | " \n", 520 | " \n", 521 | " \n", 522 | " \n", 523 | " \n", 524 | " \n", 525 | " \n", 526 | " \n", 527 | " \n", 528 | " \n", 529 | " \n", 530 | " \n", 531 | " \n", 532 | " \n", 533 | " \n", 534 | " \n", 535 | " \n", 536 | " \n", 537 | " \n", 538 | " \n", 539 | " \n", 540 | " \n", 541 | " \n", 542 | " \n", 543 | " \n", 544 | " \n", 545 | " \n", 546 | " \n", 547 | " \n", 548 | " \n", 549 | " \n", 550 | " \n", 551 | " \n", 552 | " \n", 553 | " \n", 554 | " \n", 555 | " \n", 556 | " \n", 557 | " \n", 558 | " \n", 559 | " \n", 560 | " \n", 561 | " \n", 562 | " \n", 563 | " \n", 564 | " \n", 565 | " \n", 566 | " \n", 567 | " \n", 568 | " \n", 569 | " \n", 570 | " \n", 571 | " \n", 572 | " \n", 573 | " \n", 574 | " \n", 575 | " \n", 576 | " \n", 577 | " \n", 578 | " \n", 579 | " \n", 580 | " \n", 581 | " \n", 582 | " \n", 583 | " \n", 584 | " \n", 585 | " \n", 586 | " \n", 587 | " \n", 588 | " \n", 589 | " \n", 590 | " \n", 591 | " \n", 592 | " \n", 593 | " \n", 594 | " \n", 595 | " \n", 596 | " \n", 597 | " \n", 598 | " \n", 599 | " \n", 600 | " \n", 601 | " \n", 602 | " \n", 603 | " \n", 604 | " \n", 605 | " \n", 606 | " \n", 607 | " \n", 608 | " \n", 609 | " \n", 610 | " \n", 611 | " \n", 612 | " \n", 613 | " \n", 614 | " \n", 615 | " \n", 616 | " \n", 617 | " \n", 618 | " \n", 619 | " \n", 620 | " \n", 621 | " \n", 622 | " \n", 623 | " \n", 624 | " \n", 625 | " \n", 626 | " \n", 627 | " \n", 628 | " \n", 629 | " \n", 630 | " \n", 631 | " \n", 632 | " \n", 633 | " \n", 634 | " \n", 635 | " \n", 636 | " \n", 637 | " \n", 638 | " \n", 639 | " \n", 640 | " \n", 641 | " \n", 642 | " \n", 643 | " \n", 644 | " \n", 645 | " \n", 646 | " \n", 647 | " \n", 648 | " \n", 649 | " \n", 650 | " \n", 651 | " \n", 652 | " \n", 653 | " \n", 654 | " \n", 655 | " \n", 656 | " \n", 657 | " \n", 658 | " \n", 659 | " \n", 660 | " \n", 661 | " \n", 662 | " \n", 663 | " \n", 664 | " \n", 665 | " \n", 666 | " \n", 667 | " \n", 668 | " \n", 669 | " \n", 670 | " \n", 671 | " \n", 672 | " \n", 673 | " \n", 674 | " \n", 675 | " \n", 676 | " \n", 677 | " \n", 678 | " \n", 679 | " \n", 680 | " \n", 681 | " \n", 682 | "
IDNameDOBSSN
041Ravazzolo,Charles X.1953-07-16924-20-1182
142Diavolo,Angela K.1955-08-04763-59-8356
243Drabek,Mo Q.1961-10-21538-94-9875
344Umansky,Uma T.1926-10-20896-41-7906
445Finn,Buzz D.1952-02-03210-10-9763
546Zevon,Edward C.1996-06-03661-45-8189
647Koenig,Clint H.2013-09-19642-38-5020
748Hernandez,Rhonda F.1979-04-26658-17-2445
849Donaldson,Emma W.1928-12-28689-96-9927
950Tweed,Alexandra Q.2013-02-07134-86-7366
1051Leiberman,Emma L.1953-08-21791-95-1082
1152Burroughs,Keith C.1955-02-17305-17-9685
1253Olsen,Robert B.1967-07-03918-81-2873
1354Hammel,Quentin F.1957-02-06223-47-6264
1455Ramsay,Sophia I.1977-02-15650-96-7289
1556Ragon,Jose U.1986-10-18585-74-1584
1657Gold,Violet T.1969-08-01387-37-6873
1758DeSantis,Wilma L.1924-08-02894-30-3393
1859Ingrahm,Kirsten P.1979-12-19545-28-1959
1960Chesire,Michael Y.1984-07-25402-51-9716
2061Martinez,Barbara J.2014-06-06855-88-4267
2162O'Donnell,Brenda B.2006-01-17623-88-2338
2263Gallant,Will U.1978-12-19464-47-4969
2364Clinton,Stavros O.1963-06-07647-77-3381
2465Braam,Alvin F.1959-05-21809-44-6154
2566Ingersol,Richard U.1932-05-06851-98-3939
2667Diavolo,Jules G.1933-11-30436-53-3895
2768Uberoth,Stuart F.2010-10-25308-93-8200
2869Black,Agnes O.2013-04-11324-78-7237
2970Malynko,Michael P.1962-09-18883-98-3863
3071Ott,Barb Y.2011-03-18742-20-3937
3172Ihringer,Wilma T.1925-08-02601-84-2423
3273Isaksen,Michael U.1972-07-28566-84-6943
3374Lennon,Christine X.1970-08-25187-78-5009
3475Feynman,Orson K.1948-07-29694-31-7101
3576Peters,Maria X.1934-01-28594-87-7564
3677Edison,Barb K.1941-03-14749-16-9953
3778Tsatsulin,Nellie A.1969-10-21317-74-3023
3879Adams,Stavros X.1968-12-09250-79-7429
3980Page,Laura Y.1986-12-02735-16-5768
4081Hills,Phil P.1963-11-15931-11-2763
4182Harrison,Greta U.1965-01-26627-70-2668
4283Smyth,Jocelyn Z.1940-03-06151-49-8012
4384Feynman,Zelda F.2005-04-16207-63-9461
4485Pantaleo,Bart N.1989-11-02784-84-8844
4586Townsend,Pam W.2003-10-17874-68-6763
4687Evans,Nataliya W.1950-02-15290-61-8250
4788Klein,Liza O.1958-10-16538-72-5937
4889Semmens,Filomena P.1961-01-16366-83-4774
4990Winters,Jane V.1971-03-23536-27-5329
\n", 683 | "
" 684 | ], 685 | "text/plain": [ 686 | " ID Name DOB SSN\n", 687 | "0 41 Ravazzolo,Charles X. 1953-07-16 924-20-1182\n", 688 | "1 42 Diavolo,Angela K. 1955-08-04 763-59-8356\n", 689 | "2 43 Drabek,Mo Q. 1961-10-21 538-94-9875\n", 690 | "3 44 Umansky,Uma T. 1926-10-20 896-41-7906\n", 691 | "4 45 Finn,Buzz D. 1952-02-03 210-10-9763\n", 692 | "5 46 Zevon,Edward C. 1996-06-03 661-45-8189\n", 693 | "6 47 Koenig,Clint H. 2013-09-19 642-38-5020\n", 694 | "7 48 Hernandez,Rhonda F. 1979-04-26 658-17-2445\n", 695 | "8 49 Donaldson,Emma W. 1928-12-28 689-96-9927\n", 696 | "9 50 Tweed,Alexandra Q. 2013-02-07 134-86-7366\n", 697 | "10 51 Leiberman,Emma L. 1953-08-21 791-95-1082\n", 698 | "11 52 Burroughs,Keith C. 1955-02-17 305-17-9685\n", 699 | "12 53 Olsen,Robert B. 1967-07-03 918-81-2873\n", 700 | "13 54 Hammel,Quentin F. 1957-02-06 223-47-6264\n", 701 | "14 55 Ramsay,Sophia I. 1977-02-15 650-96-7289\n", 702 | "15 56 Ragon,Jose U. 1986-10-18 585-74-1584\n", 703 | "16 57 Gold,Violet T. 1969-08-01 387-37-6873\n", 704 | "17 58 DeSantis,Wilma L. 1924-08-02 894-30-3393\n", 705 | "18 59 Ingrahm,Kirsten P. 1979-12-19 545-28-1959\n", 706 | "19 60 Chesire,Michael Y. 1984-07-25 402-51-9716\n", 707 | "20 61 Martinez,Barbara J. 2014-06-06 855-88-4267\n", 708 | "21 62 O'Donnell,Brenda B. 2006-01-17 623-88-2338\n", 709 | "22 63 Gallant,Will U. 1978-12-19 464-47-4969\n", 710 | "23 64 Clinton,Stavros O. 1963-06-07 647-77-3381\n", 711 | "24 65 Braam,Alvin F. 1959-05-21 809-44-6154\n", 712 | "25 66 Ingersol,Richard U. 1932-05-06 851-98-3939\n", 713 | "26 67 Diavolo,Jules G. 1933-11-30 436-53-3895\n", 714 | "27 68 Uberoth,Stuart F. 2010-10-25 308-93-8200\n", 715 | "28 69 Black,Agnes O. 2013-04-11 324-78-7237\n", 716 | "29 70 Malynko,Michael P. 1962-09-18 883-98-3863\n", 717 | "30 71 Ott,Barb Y. 2011-03-18 742-20-3937\n", 718 | "31 72 Ihringer,Wilma T. 1925-08-02 601-84-2423\n", 719 | "32 73 Isaksen,Michael U. 1972-07-28 566-84-6943\n", 720 | "33 74 Lennon,Christine X. 1970-08-25 187-78-5009\n", 721 | "34 75 Feynman,Orson K. 1948-07-29 694-31-7101\n", 722 | "35 76 Peters,Maria X. 1934-01-28 594-87-7564\n", 723 | "36 77 Edison,Barb K. 1941-03-14 749-16-9953\n", 724 | "37 78 Tsatsulin,Nellie A. 1969-10-21 317-74-3023\n", 725 | "38 79 Adams,Stavros X. 1968-12-09 250-79-7429\n", 726 | "39 80 Page,Laura Y. 1986-12-02 735-16-5768\n", 727 | "40 81 Hills,Phil P. 1963-11-15 931-11-2763\n", 728 | "41 82 Harrison,Greta U. 1965-01-26 627-70-2668\n", 729 | "42 83 Smyth,Jocelyn Z. 1940-03-06 151-49-8012\n", 730 | "43 84 Feynman,Zelda F. 2005-04-16 207-63-9461\n", 731 | "44 85 Pantaleo,Bart N. 1989-11-02 784-84-8844\n", 732 | "45 86 Townsend,Pam W. 2003-10-17 874-68-6763\n", 733 | "46 87 Evans,Nataliya W. 1950-02-15 290-61-8250\n", 734 | "47 88 Klein,Liza O. 1958-10-16 538-72-5937\n", 735 | "48 89 Semmens,Filomena P. 1961-01-16 366-83-4774\n", 736 | "49 90 Winters,Jane V. 1971-03-23 536-27-5329" 737 | ] 738 | }, 739 | "execution_count": 11, 740 | "metadata": {}, 741 | "output_type": "execute_result" 742 | } 743 | ], 744 | "source": [ 745 | "samples_query.display_records(50)" 746 | ] 747 | }, 748 | { 749 | "cell_type": "markdown", 750 | "metadata": {}, 751 | "source": [ 752 | "### skip records" 753 | ] 754 | }, 755 | { 756 | "cell_type": "code", 757 | "execution_count": 12, 758 | "metadata": {}, 759 | "outputs": [ 760 | { 761 | "data": { 762 | "text/html": [ 763 | "
\n", 764 | "\n", 777 | "\n", 778 | " \n", 779 | " \n", 780 | " \n", 781 | " \n", 782 | " \n", 783 | " \n", 784 | " \n", 785 | " \n", 786 | " \n", 787 | " \n", 788 | " \n", 789 | " \n", 790 | " \n", 791 | " \n", 792 | " \n", 793 | " \n", 794 | " \n", 795 | " \n", 796 | " \n", 797 | " \n", 798 | " \n", 799 | " \n", 800 | " \n", 801 | " \n", 802 | " \n", 803 | " \n", 804 | " \n", 805 | " \n", 806 | " \n", 807 | " \n", 808 | " \n", 809 | " \n", 810 | " \n", 811 | " \n", 812 | " \n", 813 | " \n", 814 | " \n", 815 | " \n", 816 | " \n", 817 | " \n", 818 | " \n", 819 | " \n", 820 | " \n", 821 | " \n", 822 | " \n", 823 | " \n", 824 | " \n", 825 | " \n", 826 | " \n", 827 | " \n", 828 | " \n", 829 | " \n", 830 | " \n", 831 | " \n", 832 | " \n", 833 | " \n", 834 | " \n", 835 | " \n", 836 | " \n", 837 | " \n", 838 | " \n", 839 | " \n", 840 | " \n", 841 | " \n", 842 | " \n", 843 | " \n", 844 | " \n", 845 | " \n", 846 | " \n", 847 | " \n", 848 | " \n", 849 | " \n", 850 | " \n", 851 | " \n", 852 | " \n", 853 | " \n", 854 | " \n", 855 | " \n", 856 | " \n", 857 | " \n", 858 | " \n", 859 | "
IDNameDOBSSN
0111Xander,Christine Q.1991-03-15629-14-6409
1112Perez,Nellie P.1960-01-06230-60-6205
2113Nichols,Vincent X.1977-04-25390-76-9829
3114King,Terry Q.1924-01-19484-96-8493
4115Jung,Terry G.1932-08-15939-47-9874
5116Evans,Pat J.1997-12-07368-93-4336
6117Cheng,Imelda H.2004-11-06866-36-5045
7118Tillem,Maria X.1941-06-13715-31-6735
8119Ingersol,Vincent O.1947-06-14867-48-2437
9120Rodriguez,Sam U.2009-03-05145-75-1244
\n", 860 | "
" 861 | ], 862 | "text/plain": [ 863 | " ID Name DOB SSN\n", 864 | "0 111 Xander,Christine Q. 1991-03-15 629-14-6409\n", 865 | "1 112 Perez,Nellie P. 1960-01-06 230-60-6205\n", 866 | "2 113 Nichols,Vincent X. 1977-04-25 390-76-9829\n", 867 | "3 114 King,Terry Q. 1924-01-19 484-96-8493\n", 868 | "4 115 Jung,Terry G. 1932-08-15 939-47-9874\n", 869 | "5 116 Evans,Pat J. 1997-12-07 368-93-4336\n", 870 | "6 117 Cheng,Imelda H. 2004-11-06 866-36-5045\n", 871 | "7 118 Tillem,Maria X. 1941-06-13 715-31-6735\n", 872 | "8 119 Ingersol,Vincent O. 1947-06-14 867-48-2437\n", 873 | "9 120 Rodriguez,Sam U. 2009-03-05 145-75-1244" 874 | ] 875 | }, 876 | "execution_count": 12, 877 | "metadata": {}, 878 | "output_type": "execute_result" 879 | } 880 | ], 881 | "source": [ 882 | "samples_query.skip_records(20)\n", 883 | "\n", 884 | "samples_query.display_records(10)" 885 | ] 886 | }, 887 | { 888 | "cell_type": "markdown", 889 | "metadata": {}, 890 | "source": [ 891 | "## Execute Call to a CACHE Class Query" 892 | ] 893 | }, 894 | { 895 | "cell_type": "code", 896 | "execution_count": 13, 897 | "metadata": {}, 898 | "outputs": [ 899 | { 900 | "name": "stdout", 901 | "output_type": "stream", 902 | "text": [ 903 | "result set is now ready and can be fetched\n" 904 | ] 905 | } 906 | ], 907 | "source": [ 908 | "samples_query.execute_call('Person', 'Extent')" 909 | ] 910 | }, 911 | { 912 | "cell_type": "code", 913 | "execution_count": 14, 914 | "metadata": {}, 915 | "outputs": [ 916 | { 917 | "data": { 918 | "text/html": [ 919 | "
\n", 920 | "\n", 933 | "\n", 934 | " \n", 935 | " \n", 936 | " \n", 937 | " \n", 938 | " \n", 939 | " \n", 940 | " \n", 941 | " \n", 942 | " \n", 943 | " \n", 944 | " \n", 945 | " \n", 946 | " \n", 947 | " \n", 948 | " \n", 949 | " \n", 950 | " \n", 951 | " \n", 952 | " \n", 953 | " \n", 954 | " \n", 955 | " \n", 956 | " \n", 957 | " \n", 958 | " \n", 959 | " \n", 960 | " \n", 961 | " \n", 962 | " \n", 963 | " \n", 964 | " \n", 965 | " \n", 966 | " \n", 967 | " \n", 968 | " \n", 969 | " \n", 970 | " \n", 971 | " \n", 972 | " \n", 973 | " \n", 974 | " \n", 975 | " \n", 976 | " \n", 977 | " \n", 978 | " \n", 979 | " \n", 980 | " \n", 981 | " \n", 982 | " \n", 983 | " \n", 984 | " \n", 985 | " \n", 986 | " \n", 987 | " \n", 988 | " \n", 989 | " \n", 990 | " \n", 991 | " \n", 992 | " \n", 993 | " \n", 994 | " \n", 995 | " \n", 996 | " \n", 997 | " \n", 998 | " \n", 999 | " \n", 1000 | " \n", 1001 | " \n", 1002 | " \n", 1003 | " \n", 1004 | " \n", 1005 | " \n", 1006 | " \n", 1007 | " \n", 1008 | " \n", 1009 | " \n", 1010 | " \n", 1011 | " \n", 1012 | " \n", 1013 | " \n", 1014 | " \n", 1015 | " \n", 1016 | " \n", 1017 | " \n", 1018 | " \n", 1019 | " \n", 1020 | " \n", 1021 | " \n", 1022 | " \n", 1023 | " \n", 1024 | " \n", 1025 | " \n", 1026 | "
IDNameSSNHome.CityHome.State
01Isaksen,Alexandra T.207-26-6677QueensburyLA
12Isaacs,Emily R.295-77-6690GansevoortSD
23Feynman,James K.928-52-1962LarchmontCO
34Vanzetti,Mary R.234-96-2703ZanesvilleMS
45Orwell,Alfred R.422-27-1069UkiahOH
56Ironhorse,Stuart F.597-44-6996IslipNE
67Browning,Mary C.692-44-7227ZanesvilleNC
78Jones,David S.269-67-6145PuebloOH
89Xavier,Dan K.335-82-9284NewtonND
910Goncharuk,Greta W.134-52-9380RestonSC
\n", 1027 | "
" 1028 | ], 1029 | "text/plain": [ 1030 | " ID Name SSN Home.City Home.State\n", 1031 | "0 1 Isaksen,Alexandra T. 207-26-6677 Queensbury LA\n", 1032 | "1 2 Isaacs,Emily R. 295-77-6690 Gansevoort SD\n", 1033 | "2 3 Feynman,James K. 928-52-1962 Larchmont CO\n", 1034 | "3 4 Vanzetti,Mary R. 234-96-2703 Zanesville MS\n", 1035 | "4 5 Orwell,Alfred R. 422-27-1069 Ukiah OH\n", 1036 | "5 6 Ironhorse,Stuart F. 597-44-6996 Islip NE\n", 1037 | "6 7 Browning,Mary C. 692-44-7227 Zanesville NC\n", 1038 | "7 8 Jones,David S. 269-67-6145 Pueblo OH\n", 1039 | "8 9 Xavier,Dan K. 335-82-9284 Newton ND\n", 1040 | "9 10 Goncharuk,Greta W. 134-52-9380 Reston SC" 1041 | ] 1042 | }, 1043 | "execution_count": 14, 1044 | "metadata": {}, 1045 | "output_type": "execute_result" 1046 | } 1047 | ], 1048 | "source": [ 1049 | "samples_query.display_records(10)" 1050 | ] 1051 | }, 1052 | { 1053 | "cell_type": "markdown", 1054 | "metadata": {}, 1055 | "source": [ 1056 | "## Execute the same query invoking the stored procedure with CALL" 1057 | ] 1058 | }, 1059 | { 1060 | "cell_type": "code", 1061 | "execution_count": 15, 1062 | "metadata": {}, 1063 | "outputs": [ 1064 | { 1065 | "name": "stdout", 1066 | "output_type": "stream", 1067 | "text": [ 1068 | "result set is now ready and can be fetched\n" 1069 | ] 1070 | }, 1071 | { 1072 | "data": { 1073 | "text/html": [ 1074 | "
\n", 1075 | "\n", 1088 | "\n", 1089 | " \n", 1090 | " \n", 1091 | " \n", 1092 | " \n", 1093 | " \n", 1094 | " \n", 1095 | " \n", 1096 | " \n", 1097 | " \n", 1098 | " \n", 1099 | " \n", 1100 | " \n", 1101 | " \n", 1102 | " \n", 1103 | " \n", 1104 | " \n", 1105 | " \n", 1106 | " \n", 1107 | " \n", 1108 | " \n", 1109 | " \n", 1110 | " \n", 1111 | " \n", 1112 | " \n", 1113 | " \n", 1114 | " \n", 1115 | " \n", 1116 | " \n", 1117 | " \n", 1118 | " \n", 1119 | " \n", 1120 | " \n", 1121 | " \n", 1122 | " \n", 1123 | " \n", 1124 | " \n", 1125 | " \n", 1126 | " \n", 1127 | " \n", 1128 | " \n", 1129 | " \n", 1130 | " \n", 1131 | " \n", 1132 | " \n", 1133 | " \n", 1134 | " \n", 1135 | " \n", 1136 | " \n", 1137 | " \n", 1138 | " \n", 1139 | " \n", 1140 | " \n", 1141 | "
IDNameSSNHome.CityHome.State
01Isaksen,Alexandra T.207-26-6677QueensburyLA
12Isaacs,Emily R.295-77-6690GansevoortSD
23Feynman,James K.928-52-1962LarchmontCO
34Vanzetti,Mary R.234-96-2703ZanesvilleMS
45Orwell,Alfred R.422-27-1069UkiahOH
\n", 1142 | "
" 1143 | ], 1144 | "text/plain": [ 1145 | " ID Name SSN Home.City Home.State\n", 1146 | "0 1 Isaksen,Alexandra T. 207-26-6677 Queensbury LA\n", 1147 | "1 2 Isaacs,Emily R. 295-77-6690 Gansevoort SD\n", 1148 | "2 3 Feynman,James K. 928-52-1962 Larchmont CO\n", 1149 | "3 4 Vanzetti,Mary R. 234-96-2703 Zanesville MS\n", 1150 | "4 5 Orwell,Alfred R. 422-27-1069 Ukiah OH" 1151 | ] 1152 | }, 1153 | "execution_count": 15, 1154 | "metadata": {}, 1155 | "output_type": "execute_result" 1156 | } 1157 | ], 1158 | "source": [ 1159 | "samples_query.execute_sql(\"CALL Sample.Person_Extent\")\n", 1160 | "samples_query.display_records(5)" 1161 | ] 1162 | }, 1163 | { 1164 | "cell_type": "markdown", 1165 | "metadata": {}, 1166 | "source": [ 1167 | "## Execute Call to a CACHE Class Query with parameter" 1168 | ] 1169 | }, 1170 | { 1171 | "cell_type": "code", 1172 | "execution_count": 16, 1173 | "metadata": {}, 1174 | "outputs": [ 1175 | { 1176 | "name": "stdout", 1177 | "output_type": "stream", 1178 | "text": [ 1179 | "result set is now ready and can be fetched\n", 1180 | "Execution reached the end of the result set\n" 1181 | ] 1182 | }, 1183 | { 1184 | "data": { 1185 | "text/html": [ 1186 | "
\n", 1187 | "\n", 1200 | "\n", 1201 | " \n", 1202 | " \n", 1203 | " \n", 1204 | " \n", 1205 | " \n", 1206 | " \n", 1207 | " \n", 1208 | " \n", 1209 | " \n", 1210 | " \n", 1211 | " \n", 1212 | " \n", 1213 | " \n", 1214 | " \n", 1215 | " \n", 1216 | " \n", 1217 | " \n", 1218 | " \n", 1219 | " \n", 1220 | " \n", 1221 | " \n", 1222 | " \n", 1223 | " \n", 1224 | " \n", 1225 | " \n", 1226 | " \n", 1227 | " \n", 1228 | " \n", 1229 | " \n", 1230 | " \n", 1231 | " \n", 1232 | " \n", 1233 | " \n", 1234 | " \n", 1235 | " \n", 1236 | " \n", 1237 | " \n", 1238 | " \n", 1239 | " \n", 1240 | "
IDNameDOBSSN
0175Adam,Lisa H.1927-10-09252-98-5363
1154Adams,Liza Z.1996-10-01473-63-1193
279Adams,Stavros X.1968-12-09250-79-7429
3123Alton,Frances S.1946-07-30956-58-1061
\n", 1241 | "
" 1242 | ], 1243 | "text/plain": [ 1244 | " ID Name DOB SSN\n", 1245 | "0 175 Adam,Lisa H. 1927-10-09 252-98-5363\n", 1246 | "1 154 Adams,Liza Z. 1996-10-01 473-63-1193\n", 1247 | "2 79 Adams,Stavros X. 1968-12-09 250-79-7429\n", 1248 | "3 123 Alton,Frances S. 1946-07-30 956-58-1061" 1249 | ] 1250 | }, 1251 | "execution_count": 16, 1252 | "metadata": {}, 1253 | "output_type": "execute_result" 1254 | } 1255 | ], 1256 | "source": [ 1257 | "samples_query.execute_call('Person', 'ByName', 'A')\n", 1258 | "samples_query.display_records(5)" 1259 | ] 1260 | }, 1261 | { 1262 | "cell_type": "markdown", 1263 | "metadata": {}, 1264 | "source": [ 1265 | "## Execute SQL SELECT query with a single parameter" 1266 | ] 1267 | }, 1268 | { 1269 | "cell_type": "code", 1270 | "execution_count": 17, 1271 | "metadata": {}, 1272 | "outputs": [ 1273 | { 1274 | "name": "stdout", 1275 | "output_type": "stream", 1276 | "text": [ 1277 | "result set is now ready and can be fetched\n", 1278 | "Execution reached the end of the result set\n" 1279 | ] 1280 | }, 1281 | { 1282 | "data": { 1283 | "text/html": [ 1284 | "
\n", 1285 | "\n", 1298 | "\n", 1299 | " \n", 1300 | " \n", 1301 | " \n", 1302 | " \n", 1303 | " \n", 1304 | " \n", 1305 | " \n", 1306 | " \n", 1307 | " \n", 1308 | " \n", 1309 | " \n", 1310 | " \n", 1311 | " \n", 1312 | " \n", 1313 | " \n", 1314 | " \n", 1315 | " \n", 1316 | " \n", 1317 | " \n", 1318 | " \n", 1319 | " \n", 1320 | " \n", 1321 | " \n", 1322 | " \n", 1323 | " \n", 1324 | " \n", 1325 | " \n", 1326 | " \n", 1327 | " \n", 1328 | " \n", 1329 | " \n", 1330 | " \n", 1331 | " \n", 1332 | " \n", 1333 | " \n", 1334 | " \n", 1335 | " \n", 1336 | " \n", 1337 | " \n", 1338 | "
IDNameDOBSSN
079Adams,Stavros X.1968-12-09250-79-7429
1123Alton,Frances S.1946-07-30956-58-1061
2154Adams,Liza Z.1996-10-01473-63-1193
3175Adam,Lisa H.1927-10-09252-98-5363
\n", 1339 | "
" 1340 | ], 1341 | "text/plain": [ 1342 | " ID Name DOB SSN\n", 1343 | "0 79 Adams,Stavros X. 1968-12-09 250-79-7429\n", 1344 | "1 123 Alton,Frances S. 1946-07-30 956-58-1061\n", 1345 | "2 154 Adams,Liza Z. 1996-10-01 473-63-1193\n", 1346 | "3 175 Adam,Lisa H. 1927-10-09 252-98-5363" 1347 | ] 1348 | }, 1349 | "execution_count": 17, 1350 | "metadata": {}, 1351 | "output_type": "execute_result" 1352 | } 1353 | ], 1354 | "source": [ 1355 | "sqlstr = \"SELECT ID, Name, DOB, SSN \\\n", 1356 | " FROM SAMPLE.PERSON \\\n", 1357 | " WHERE Name %STARTSWITH ?\"\n", 1358 | "\n", 1359 | "samples_query.execute_sql(sqlstr,'A')\n", 1360 | "samples_query.display_records(5)" 1361 | ] 1362 | }, 1363 | { 1364 | "cell_type": "code", 1365 | "execution_count": null, 1366 | "metadata": { 1367 | "collapsed": true 1368 | }, 1369 | "outputs": [], 1370 | "source": [] 1371 | } 1372 | ], 1373 | "metadata": { 1374 | "kernelspec": { 1375 | "display_name": "Python 3", 1376 | "language": "python", 1377 | "name": "python3" 1378 | }, 1379 | "language_info": { 1380 | "codemirror_mode": { 1381 | "name": "ipython", 1382 | "version": 3 1383 | }, 1384 | "file_extension": ".py", 1385 | "mimetype": "text/x-python", 1386 | "name": "python", 1387 | "nbconvert_exporter": "python", 1388 | "pygments_lexer": "ipython3", 1389 | "version": "3.6.3" 1390 | } 1391 | }, 1392 | "nbformat": 4, 1393 | "nbformat_minor": 2 1394 | } 1395 | --------------------------------------------------------------------------------