BooleanVar.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //-----------------------------------------------------------------------------
  2. // BooleanVar.c
  3. // Defines the routines for handling boolean variables (only available after
  4. // Oracle 12.1).
  5. //-----------------------------------------------------------------------------
  6. //-----------------------------------------------------------------------------
  7. // Data types
  8. //-----------------------------------------------------------------------------
  9. typedef struct {
  10. Variable_HEAD
  11. int *data;
  12. } udt_BooleanVar;
  13. //-----------------------------------------------------------------------------
  14. // Declaration of variable functions.
  15. //-----------------------------------------------------------------------------
  16. static int BooleanVar_SetValue(udt_BooleanVar*, unsigned, PyObject*);
  17. static PyObject *BooleanVar_GetValue(udt_BooleanVar*, unsigned);
  18. //-----------------------------------------------------------------------------
  19. // Python type declaration
  20. //-----------------------------------------------------------------------------
  21. static PyTypeObject g_BooleanVarType = {
  22. PyVarObject_HEAD_INIT(NULL, 0)
  23. "cx_Oracle.BOOLEAN", // tp_name
  24. sizeof(udt_BooleanVar), // tp_basicsize
  25. 0, // tp_itemsize
  26. 0, // tp_dealloc
  27. 0, // tp_print
  28. 0, // tp_getattr
  29. 0, // tp_setattr
  30. 0, // tp_compare
  31. 0, // tp_repr
  32. 0, // tp_as_number
  33. 0, // tp_as_sequence
  34. 0, // tp_as_mapping
  35. 0, // tp_hash
  36. 0, // tp_call
  37. 0, // tp_str
  38. 0, // tp_getattro
  39. 0, // tp_setattro
  40. 0, // tp_as_buffer
  41. Py_TPFLAGS_DEFAULT, // tp_flags
  42. 0 // tp_doc
  43. };
  44. //-----------------------------------------------------------------------------
  45. // variable type declarations
  46. //-----------------------------------------------------------------------------
  47. static udt_VariableType vt_Boolean = {
  48. (InitializeProc) NULL,
  49. (FinalizeProc) NULL,
  50. (PreDefineProc) NULL,
  51. (PostDefineProc) NULL,
  52. (PreFetchProc) NULL,
  53. (IsNullProc) NULL,
  54. (SetValueProc) BooleanVar_SetValue,
  55. (GetValueProc) BooleanVar_GetValue,
  56. (GetBufferSizeProc) NULL,
  57. &g_BooleanVarType, // Python type
  58. SQLT_BOL, // Oracle type
  59. SQLCS_IMPLICIT, // charset form
  60. sizeof(int), // element length
  61. 0, // is character data
  62. 0, // is variable length
  63. 1, // can be copied
  64. 0 // can be in array
  65. };
  66. //-----------------------------------------------------------------------------
  67. // BooleanVar_GetValue()
  68. // Returns the value stored at the given array position.
  69. //-----------------------------------------------------------------------------
  70. static PyObject *BooleanVar_GetValue(
  71. udt_BooleanVar *var, // variable to determine value for
  72. unsigned pos) // array position
  73. {
  74. int integerValue;
  75. PyObject *value;
  76. integerValue = var->data[pos];
  77. value = (integerValue) ? Py_True : Py_False;
  78. Py_INCREF(value);
  79. return value;
  80. }
  81. //-----------------------------------------------------------------------------
  82. // BooleanVar_SetValue()
  83. // Set the value of the variable at the given array position.
  84. //-----------------------------------------------------------------------------
  85. static int BooleanVar_SetValue(
  86. udt_BooleanVar *var, // variable to set value for
  87. unsigned pos, // array position to set
  88. PyObject *value) // value to set
  89. {
  90. var->data[pos] = (value == Py_True);
  91. return 0;
  92. }