# 
#  Licensed Materials - Property of IBM
#
#  (c) Copyright IBM Corp. 2007-2008
#

import unittest, sys
import ibm_db
import config
from testfunctions import IbmDbTestFunctions

class IbmDbTestCase(unittest.TestCase):

  def test_111_FieldNumAddCol(self):
    obj = IbmDbTestFunctions()
    obj.assert_expect(self.run_test_111)

  def run_test_111(self):
    conn = ibm_db.connect(config.database, config.user, config.password)
    server = ibm_db.server_info( conn )

    if conn:
      ibm_db.autocommit(conn, ibm_db.SQL_AUTOCOMMIT_OFF)

      insert = "INSERT INTO animals values (7, 'cat', 'Benji', 5.1)"
      ibm_db.exec_immediate(conn, insert)
      
      stmt = ibm_db.exec_immediate(conn, "SELECT breed, COUNT(breed) AS number FROM animals GROUP BY breed ORDER BY breed")
    
      if (server.DBMS_NAME[0:3] == 'IDS'):
        num1 = ibm_db.field_num(stmt, "id")
        num2 = ibm_db.field_num(stmt, "breed")
        num3 = ibm_db.field_num(stmt, "number")
        num4 = ibm_db.field_num(stmt, "NUMBER")
        num5 = ibm_db.field_num(stmt, "bREED")
        num6 = ibm_db.field_num(stmt, 8)
        num7 = ibm_db.field_num(stmt, 1)
        num8 = ibm_db.field_num(stmt, "WEIGHT")
      else:
        num1 = ibm_db.field_num(stmt, "ID")
        num2 = ibm_db.field_num(stmt, "BREED")
        num3 = ibm_db.field_num(stmt, "NUMBER")
        num4 = ibm_db.field_num(stmt, "number")
        num5 = ibm_db.field_num(stmt, "Breed")
        num6 = ibm_db.field_num(stmt, 8)
        num7 = ibm_db.field_num(stmt, 1)
        num8 = ibm_db.field_num(stmt, "weight")
  
      print("%s" % num1)
      print("int(%d)" % num2)
      print("int(%d)" % num3)
      print("%s" % num4)
      
      print("%s" % num5)
      print("%s" % num6)
      print("int(%d)" % num7)
      print("%s" % num8)

      ibm_db.rollback(conn)
    else:
      print("Connection failed.")

#__END__
#__LUW_EXPECTED__
#False
#int(0)
#int(1)
#False
#False
#False
#int(1)
#False
#__ZOS_EXPECTED__
#False
#int(0)
#int(1)
#False
#False
#False
#int(1)
#False
#__SYSTEMI_EXPECTED__
#False
#int(0)
#int(1)
#False
#False
#False
#int(1)
#False
#__IDS_EXPECTED__
#False
#int(0)
#int(1)
#False
#False
#False
#int(1)
#False

[((268, 288), 'testfunctions.IbmDbTestFunctions', 'IbmDbTestFunctions', ([], {}), '()\n', (286, 288), False, 'from testfunctions import IbmDbTestFunctions\n'), ((368, 429), 'ibm_db.connect', 'ibm_db.connect', (['config.database', 'config.user', 'config.password'], {}), '(config.database, config.user, config.password)\n', (382, 429), False, 'import ibm_db\n'), ((443, 467), 'ibm_db.server_info', 'ibm_db.server_info', (['conn'], {}), '(conn)\n', (461, 467), False, 'import ibm_db\n'), ((490, 540), 'ibm_db.autocommit', 'ibm_db.autocommit', (['conn', 'ibm_db.SQL_AUTOCOMMIT_OFF'], {}), '(conn, ibm_db.SQL_AUTOCOMMIT_OFF)\n', (507, 540), False, 'import ibm_db\n'), ((617, 652), 'ibm_db.exec_immediate', 'ibm_db.exec_immediate', (['conn', 'insert'], {}), '(conn, insert)\n', (638, 652), False, 'import ibm_db\n'), ((673, 792), 'ibm_db.exec_immediate', 'ibm_db.exec_immediate', (['conn', '"""SELECT breed, COUNT(breed) AS number FROM animals GROUP BY breed ORDER BY breed"""'], {}), "(conn,\n    'SELECT breed, COUNT(breed) AS number FROM animals GROUP BY breed ORDER BY breed'\n    )\n", (694, 792), False, 'import ibm_db\n'), ((1804, 1825), 'ibm_db.rollback', 'ibm_db.rollback', (['conn'], {}), '(conn)\n', (1819, 1825), False, 'import ibm_db\n'), ((847, 875), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""id"""'], {}), "(stmt, 'id')\n", (863, 875), False, 'import ibm_db\n'), ((891, 922), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""breed"""'], {}), "(stmt, 'breed')\n", (907, 922), False, 'import ibm_db\n'), ((938, 970), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""number"""'], {}), "(stmt, 'number')\n", (954, 970), False, 'import ibm_db\n'), ((986, 1018), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""NUMBER"""'], {}), "(stmt, 'NUMBER')\n", (1002, 1018), False, 'import ibm_db\n'), ((1034, 1065), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""bREED"""'], {}), "(stmt, 'bREED')\n", (1050, 1065), False, 'import ibm_db\n'), ((1081, 1106), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '(8)'], {}), '(stmt, 8)\n', (1097, 1106), False, 'import ibm_db\n'), ((1122, 1147), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '(1)'], {}), '(stmt, 1)\n', (1138, 1147), False, 'import ibm_db\n'), ((1163, 1195), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""WEIGHT"""'], {}), "(stmt, 'WEIGHT')\n", (1179, 1195), False, 'import ibm_db\n'), ((1223, 1251), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""ID"""'], {}), "(stmt, 'ID')\n", (1239, 1251), False, 'import ibm_db\n'), ((1267, 1298), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""BREED"""'], {}), "(stmt, 'BREED')\n", (1283, 1298), False, 'import ibm_db\n'), ((1314, 1346), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""NUMBER"""'], {}), "(stmt, 'NUMBER')\n", (1330, 1346), False, 'import ibm_db\n'), ((1362, 1394), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""number"""'], {}), "(stmt, 'number')\n", (1378, 1394), False, 'import ibm_db\n'), ((1410, 1441), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""Breed"""'], {}), "(stmt, 'Breed')\n", (1426, 1441), False, 'import ibm_db\n'), ((1457, 1482), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '(8)'], {}), '(stmt, 8)\n', (1473, 1482), False, 'import ibm_db\n'), ((1498, 1523), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '(1)'], {}), '(stmt, 1)\n', (1514, 1523), False, 'import ibm_db\n'), ((1539, 1571), 'ibm_db.field_num', 'ibm_db.field_num', (['stmt', '"""weight"""'], {}), "(stmt, 'weight')\n", (1555, 1571), False, 'import ibm_db\n')]