Skip to content

Commit

Permalink
Doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Satyan committed Oct 18, 2018
1 parent d6e137a commit ddbfdfd
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 38 deletions.
18 changes: 16 additions & 2 deletions Examples/Sample1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

# Sample1.py
import IfxPy

def my_Sample():
Expand Down Expand Up @@ -29,19 +30,24 @@ def my_Sample():
stmt = IfxPy.exec_immediate(conn, sql)
except:
print ('FYI: drop table failed')


i = 0
for sql in SetupSqlSet:
i += 1
print (sql)
stmt = IfxPy.exec_immediate(conn, sql)

# The first record executed is for create table
i -= 1

# Select records
sql = "SELECT * FROM t1"
stmt = IfxPy.exec_immediate(conn, sql)
dictionary = IfxPy.fetch_both(stmt)

rc = 0
while dictionary != False:
rc = rc + 1
rc += 1
print ("-- Record {0} --".format(rc))
print ("c1 is : ", dictionary[0])
print ("c2 is : ", dictionary[1])
Expand All @@ -50,6 +56,14 @@ def my_Sample():
print (" ")
dictionary = IfxPy.fetch_both(stmt)

print()
print( "Total Record Inserted {}".format(i) )
print( "Total Record Selected {}".format(rc) )

# Free up memory used by result and then stmt too
IfxPy.free_result(stmt)
IfxPy.free_stmt (stmt)

IfxPy.close(conn)

print ("Done")
Expand Down
36 changes: 22 additions & 14 deletions Examples/Sample2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

# Sample2.py
import IfxPy


Expand Down Expand Up @@ -32,36 +32,44 @@ def my_Sample():
c2 = None
c3 = None
c4 = None
# Create bindings for the parameter
IfxPy.bind_param(stmt, 1, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)
IfxPy.bind_param(stmt, 2, c2, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_CHAR)
IfxPy.bind_param(stmt, 3, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)
IfxPy.bind_param(stmt, 4, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)

i = 1
print("Inserting Recors ......")
i = 0
while i < 10:
i += 1
c1 = 100 + i
c2 = "Testing {0}".format(i)
c3 = 20000 + i
c4 = 50000 + i
# supply new values as a tuple
IfxPy.execute(stmt, (c1, c2, c3, c4) )
i += 1


# Try select those rows we have just inserted
print("Selecting Recors ......")
sql = "SELECT * FROM t1"
stmt = IfxPy.exec_immediate(conn, sql)
dictionary = IfxPy.fetch_both(stmt)

tu = IfxPy.fetch_tuple(stmt)
rc = 0
while dictionary != False:
rc = rc + 1
print ("-- Record {0} --".format(rc))
print ("c1 is : ", dictionary[0])
print ("c2 is : ", dictionary[1])
print ("c3 is : ", dictionary["c3"])
print ("c4 is : ", dictionary[3])
print (" ")
dictionary = IfxPy.fetch_both(stmt)
while tu != False:
rc += 1
print( tu )
tu = IfxPy.fetch_tuple(stmt)

print()
print( "Total Record Inserted {}".format(i) )
print( "Total Record Selected {}".format(rc) )

# Free up memory used by result and then stmt too
IfxPy.free_result(stmt)
IfxPy.free_stmt (stmt)

# close the connection
IfxPy.close(conn)

print ("Done")
Expand Down
1 change: 0 additions & 1 deletion IfxPy/tests/test_156_FetchAssocNestedSelects_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#

# This test will use a lot of the heap size allocated
# for DB2. If is is failing on your system, please
# increase the application heap size.

import unittest, sys
Expand Down
8 changes: 4 additions & 4 deletions IfxPy/tests/test_6528_ScopingProblemBindParam.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ def test_6528_ScopingProblemBindParam(self):
obj = IfxPyTestFunctions()
obj.assert_expect(self.run_test_6528)

def checked_db2_execute(self, stmt):
def checked_ids_execute(self, stmt):
IfxPy.execute(stmt)
row = IfxPy.fetch_tuple(stmt)
for i in row:
print i

def run_test_6528(self):
conn = IfxPy.connect(config.ConnStr, config.user, config.password)
server = IfxPy.server_info( conn )

if conn:
if (server.DBMS_NAME[0:3] == 'Inf'):
sql = "SELECT TRIM(TRAILING FROM name) FROM animals WHERE breed = ?"
Expand All @@ -33,7 +33,7 @@ def run_test_6528(self):
stmt = IfxPy.prepare(conn, sql)
var = "cat"
IfxPy.bind_param(stmt, 1, var, IfxPy.SQL_PARAM_INPUT)
self.checked_db2_execute(stmt)
self.checked_ids_execute(stmt)
IfxPy.close(conn)
else:
print "Connection failed."
Expand Down
64 changes: 47 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ IfxPy.close(conn)


#### Simple Query
The driver APIs used in this example are from the set of **Advanced native extension module APIs**
The driver APIs used in this example are from the set of **Advanced native extension module APIs**

##### FYI: IfxPy fetch functions
* IfxPy.fetch_tuple()
Expand All @@ -99,9 +99,15 @@ Returns a dictionary, indexed by both column name and position, representing a r
* IfxPy.fetch_row()
Sets the result set pointer to the next row or requested row. Use this function to iterate through a result set.

* free_result()
Frees resources associated with a result set

* free_stmt()
Frees resources associated with the indicated statement resource

```python

```python
# Sample1.py
import IfxPy

def my_Sample():
Expand Down Expand Up @@ -133,18 +139,23 @@ def my_Sample():
except:
print ('FYI: drop table failed')

i = 0
for sql in SetupSqlSet:
i += 1
print (sql)
stmt = IfxPy.exec_immediate(conn, sql)

# The first record executed is for create table
i -= 1

# Select records
sql = "SELECT * FROM t1"
stmt = IfxPy.exec_immediate(conn, sql)
dictionary = IfxPy.fetch_both(stmt)

rc = 0
while dictionary != False:
rc = rc + 1
rc += 1
print ("-- Record {0} --".format(rc))
print ("c1 is : ", dictionary[0])
print ("c2 is : ", dictionary[1])
Expand All @@ -153,18 +164,28 @@ def my_Sample():
print (" ")
dictionary = IfxPy.fetch_both(stmt)

print()
print( "Total Record Inserted {}".format(i) )
print( "Total Record Selected {}".format(rc) )

# Free up memory used by result and then stmt too
IfxPy.free_result(stmt)
IfxPy.free_stmt (stmt)

IfxPy.close(conn)

print ("Done")

####### Run the sample function ######
my_Sample()

```

---
#### Param Binding
```python

```python
# Sample2.py
import IfxPy


Expand Down Expand Up @@ -198,43 +219,52 @@ def my_Sample():
c2 = None
c3 = None
c4 = None
# Create bindings for the parameter
IfxPy.bind_param(stmt, 1, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)
IfxPy.bind_param(stmt, 2, c2, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_CHAR)
IfxPy.bind_param(stmt, 3, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)
IfxPy.bind_param(stmt, 4, c1, IfxPy.SQL_PARAM_INPUT, IfxPy.SQL_INTEGER)

i = 1
print("Inserting Recors ......")
i = 0
while i < 10:
i += 1
c1 = 100 + i
c2 = "Testing {0}".format(i)
c3 = 20000 + i
c4 = 50000 + i
# supply new values as a tuple
IfxPy.execute(stmt, (c1, c2, c3, c4) )
i += 1


# Try select those rows we have just inserted
print("Selecting Recors ......")
sql = "SELECT * FROM t1"
stmt = IfxPy.exec_immediate(conn, sql)
dictionary = IfxPy.fetch_both(stmt)

tu = IfxPy.fetch_tuple(stmt)
rc = 0
while dictionary != False:
rc = rc + 1
print ("-- Record {0} --".format(rc))
print ("c1 is : ", dictionary[0])
print ("c2 is : ", dictionary[1])
print ("c3 is : ", dictionary["c3"])
print ("c4 is : ", dictionary[3])
print (" ")
dictionary = IfxPy.fetch_both(stmt)
while tu != False:
rc += 1
print( tu )
tu = IfxPy.fetch_tuple(stmt)

print()
print( "Total Record Inserted {}".format(i) )
print( "Total Record Selected {}".format(rc) )

# Free up memory used by result and then stmt too
IfxPy.free_result(stmt)
IfxPy.free_stmt (stmt)

# close the connection
IfxPy.close(conn)

print ("Done")

####### Run the sample function ######
my_Sample()


```


Expand Down

0 comments on commit ddbfdfd

Please sign in to comment.