def _NumOfCols(self):
"""Get the number of cols"""
if not self.connection:
self.close()
NOC = c_short()
ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
if ret != SQL_SUCCESS:
check_success(self, ret)
return NOC.value
python类c_short()的实例源码
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
def test_byref_pointerpointer(self):
# See above
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
if c_int != c_long:
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
def addc(self, a, b, c):
if 0 == self.pc_state.P.get_D():
r = ctypes.c_short(a + b + c).value
rc = ctypes.c_byte(a + b + c).value
self.pc_state.P.set_N((0,1)[0x80 == (rc & 0x80)])
self.pc_state.P.set_Z((0,1)[rc == 0x0])
self.pc_state.P.set_V((0,1)[rc != r]) # Overflow
r = ((a & 0xFF) + (b & 0xFF) + c) & 0xFFFF
self.pc_state.P.set_C((0,1)[0x100 == (r & 0x100)])
result = (a + b + c)
elif 1 == self.pc_state.P.get_D():
# Decimal Addition
# FIXME need to fix flags
#
r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) + ((b>>4) & 0xF)* 10 + ((b & 0xF) %10) + c).value
rc = ctypes.c_byte(a + b + c).value # ???? TODO
self.pc_state.P.set_N((0,1)[r < 0])
self.pc_state.P.set_Z((0,1)[rc == 0x0])
# self.pc_state.P.V = (rc != r) ? 1:0; # Overflow
self.pc_state.P.set_C((0,1)[(r > 99) or (r < 0)])
result = (((((r/10) % 10) << 4) & 0xf0) + (r%10))
return result & 0xFF
def subc(self, a, b, c):
if 0 == self.pc_state.P.get_D():
r = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value - ctypes.c_byte(c).value).value
rs = ctypes.c_byte((a - b - c) & 0xFF).value
self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)]) # Negative
self.pc_state.P.set_Z((0,1)[rs == 0]) # Zero
self.pc_state.P.set_V((0,1)[r != rs]) # Overflow
r = a - b - c
self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow
result = a - b - c
elif 1 == self.pc_state.P.get_D():
# Decimal subtraction
# FIXME need to fix flags
r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) - (((b>>4) & 0xF)* 10 + ((b & 0xF) %10)) - c).value
# rc = a + b + c
self.pc_state.P.set_N((0,1)[r < 0])
self.pc_state.P.set_Z((0,1)[r == 0x0])
# Need to check/fix conditions for V
# self.pc_state.P.V = (rc != r) ? 1:0; # Overflow
self.pc_state.P.set_V(1) # Overflow
self.pc_state.P.set_C((0,1)[(r >= 0) and (r <= 99)])
result = (((int(r/10) % 10) << 4) & 0xf0) + (r%10)
return result & 0xFF
def cmp(self, a, b):
r = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value).value
rs = ctypes.c_byte(a - b).value
self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)]) # Negative
self.pc_state.P.set_Z((0,1)[rs == 0]) # Zero
r = (a & 0xFF) - (b & 0xFF)
self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow)
def addc(self, a, b, c):
if 0 == self.pc_state.P.get_D():
r = ctypes.c_short(a + b + c).value
rc = ctypes.c_byte(a + b + c).value
self.pc_state.P.set_N((0,1)[0x80 == (rc & 0x80)])
self.pc_state.P.set_Z((0,1)[rc == 0x0])
self.pc_state.P.set_V((0,1)[rc != r]) # Overflow
r = ((a & 0xFF) + (b & 0xFF) + c) & 0xFFFF
self.pc_state.P.set_C((0,1)[0x100 == (r & 0x100)])
result = (a + b + c)
elif 1 == self.pc_state.P.get_D():
# Decimal Addition
# FIXME need to fix flags
#
r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) + ((b>>4) & 0xF)* 10 + ((b & 0xF) %10) + c).value
rc = ctypes.c_byte(a + b + c).value # ???? TODO
self.pc_state.P.set_N((0,1)[r < 0])
self.pc_state.P.set_Z((0,1)[rc == 0x0])
# self.pc_state.P.V = (rc != r) ? 1:0; # Overflow
self.pc_state.P.set_C((0,1)[(r > 99) or (r < 0)])
result = ((((int(r/10) % 10) << 4) & 0xf0) + (r%10))
return result & 0xFF
def subc(self, a, b, c):
if 0 == self.pc_state.P.get_D():
r = ctypes.c_short(ctypes.c_byte(a).value - ctypes.c_byte(b).value - ctypes.c_byte(c).value).value
rs = ctypes.c_byte((a - b - c) & 0xFF).value
self.pc_state.P.set_N((0,1)[0x80 == (rs & 0x80)]) # Negative
self.pc_state.P.set_Z((0,1)[rs == 0]) # Zero
self.pc_state.P.set_V((0,1)[r != rs]) # Overflow
r = a - b - c
self.pc_state.P.set_C((1,0)[0x100 == (r & 0x100)]) # Carry (not borrow
result = a - b - c
elif 1 == self.pc_state.P.get_D():
# Decimal subtraction
# FIXME need to fix flags
r = ctypes.c_short(((a >> 4) & 0xF)* 10+ ((a & 0xF) %10) - (((b>>4) & 0xF)* 10 + ((b & 0xF) %10)) - c).value
# rc = a + b + c
self.pc_state.P.set_N((0,1)[r < 0])
self.pc_state.P.set_Z((0,1)[r == 0x0])
# Need to check/fix conditions for V
# self.pc_state.P.V = (rc != r) ? 1:0; # Overflow
self.pc_state.P.set_V(1) # Overflow
self.pc_state.P.set_C((0,1)[(r >= 0) and (r <= 99)])
result = (((int(r/10) % 10) << 4) & 0xf0) + (r%10)
return result & 0xFF
def GetInt16(self):
value = C.c_short()
self._GetInt16(self.handle, C.byref(value))
return value.value
def _NumOfCols(self):
"""Get the number of cols"""
if not self.connection:
self.close()
NOC = c_short()
ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
if ret != SQL_SUCCESS:
check_success(self, ret)
return NOC.value
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
def test_byref_pointerpointer(self):
# See above
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
if c_int != c_long:
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])
# Pointers are only compatible with arrays containing items of
# the same type!
LPINT = POINTER(c_int)
LPINT.from_param((c_int*3)())
self.assertRaises(TypeError, LPINT.from_param, c_short*3)
self.assertRaises(TypeError, LPINT.from_param, c_long*3)
self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
def test_byref_pointerpointer(self):
# See above
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
if c_int != c_long:
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])
# Pointers are only compatible with arrays containing items of
# the same type!
LPINT = POINTER(c_int)
LPINT.from_param((c_int*3)())
self.assertRaises(TypeError, LPINT.from_param, c_short*3)
self.assertRaises(TypeError, LPINT.from_param, c_long*3)
self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
def test_byref_pointer(self):
# The from_param class method of POINTER(typ) classes accepts what is
# returned by byref(obj), it type(obj) == typ
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPINT = POINTER(c_int)
LPINT.from_param(byref(c_int(42)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_short(22)))
if c_int != c_long:
self.assertRaises(TypeError, LPINT.from_param, byref(c_long(22)))
self.assertRaises(TypeError, LPINT.from_param, byref(c_uint(22)))
def test_byref_pointerpointer(self):
# See above
from ctypes import c_short, c_uint, c_int, c_long, pointer, POINTER, byref
LPLPINT = POINTER(POINTER(c_int))
LPLPINT.from_param(byref(pointer(c_int(42))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_short(22))))
if c_int != c_long:
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_long(22))))
self.assertRaises(TypeError, LPLPINT.from_param, byref(pointer(c_uint(22))))
def test_array_pointers(self):
from ctypes import c_short, c_uint, c_int, c_long, POINTER
INTARRAY = c_int * 3
ia = INTARRAY()
self.assertEqual(len(ia), 3)
self.assertEqual([ia[i] for i in range(3)], [0, 0, 0])
# Pointers are only compatible with arrays containing items of
# the same type!
LPINT = POINTER(c_int)
LPINT.from_param((c_int*3)())
self.assertRaises(TypeError, LPINT.from_param, c_short*3)
self.assertRaises(TypeError, LPINT.from_param, c_long*3)
self.assertRaises(TypeError, LPINT.from_param, c_uint*3)
def _NumOfCols(self):
"""Get the number of cols"""
if not self.connection:
self.close()
NOC = c_short()
ret = SQLNumResultCols(self.stmt_h, ADDR(NOC))
if ret != SQL_SUCCESS:
check_success(self, ret)
return NOC.value