xugusql_cgo.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package xugusql
  2. import (
  3. "unsafe"
  4. )
  5. /*
  6. #cgo CFLAGS : -I/usr/include
  7. #cgo LDFLAGS : -L/usr/lib64 -lxugusql
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "xugusql.h"
  11. */
  12. import "C"
  13. var IPS_COUNTER int = 0
  14. var IPS_BODY unsafe.Pointer
  15. /* Collect error information from the database server */
  16. func cgo_xgc_error(__pConn *unsafe.Pointer, pLog *C.char, act *C.int) int {
  17. return int(C.XGC_GetError(__pConn, pLog, act))
  18. }
  19. /*
  20. * 'C.XGC_OpenConn' is used to establish a new connection session with XGDB,
  21. * return value:
  22. * (int) 2 : Success (int)-1 : Failure
  23. * (int)-8 : TCP/IP socket error. (int)-9 : Login xgdb failure.
  24. */
  25. func cgo_xgc_connect(pdsn *C.char, __pConn *unsafe.Pointer) int {
  26. return int(C.XGC_OpenConn(pdsn, __pConn))
  27. }
  28. /* 'C.XGC_OpenConn_Ips' is used to establish a new connection session with XGDB,
  29. * it is different from'C.XGC_OpenConn' in that'C.XGC_OpenConn_Ips' can achieve
  30. * connection load balancing between distributed database nodes.
  31. */
  32. func cgo_xgc_connect_ips(pdsn *C.char, __pConn *unsafe.Pointer) int {
  33. return int(C.XGC_OpenConn_Ips(pdsn, C.int(IPS_COUNTER), &IPS_BODY, __pConn))
  34. }
  35. /*
  36. * The cgo-level call,
  37. * to realize the user's memory allocation application.
  38. */
  39. func cgo_c_calloc(Size uint) *C.char {
  40. return (*C.char)(C.calloc(C.ulong(1), C.ulong(Size)))
  41. }
  42. /*
  43. * The cgo-level call,
  44. * to cleans up the data in the memory requested by cgo_c_calloc.
  45. */
  46. func cgo_c_memset(pointer *C.char, length uint) {
  47. C.memset(unsafe.Pointer(pointer), 0x0, C.ulong(length))
  48. }
  49. /*
  50. * The cgo-level call,
  51. * releases the memory requested by cgo_c_calloc.
  52. */
  53. func cgo_c_free(__Pr unsafe.Pointer) {
  54. C.free(__Pr)
  55. }
  56. // Execute SQL statements without result set return, including DDL and DML
  57. func cgo_xgc_execnoquery(__pConn *unsafe.Pointer, query *C.char) int {
  58. return int(C.XGC_Execute_no_query(__pConn, query))
  59. }
  60. /*
  61. * Return the type of the SQL statement,
  62. * confirm it is DDL, DML and DQL.
  63. */
  64. func cgo_xgc_sql_type(sql *C.char) int {
  65. return int(C.fun_sql_type(sql))
  66. }
  67. /*
  68. * Binding parameters,
  69. * the binding method uses the form of placeholders.
  70. */
  71. func cgo_xgc_bindparambypos(__pConn *unsafe.Pointer, seq int, ArgType int,
  72. Type int, Valu unsafe.Pointer, Buff C.int, act *C.int) int {
  73. return int(C.XGC_BindParamByPos(__pConn, C.int(seq), C.int(ArgType),
  74. C.int(Type), Valu, Buff, act))
  75. }
  76. /*
  77. * Binding parameters,
  78. * the binding method uses the form of the parameter name.
  79. */
  80. func cgo_xgc_bindparambyname(__pConn *unsafe.Pointer, Name *C.char, ArgType int,
  81. Type int, Valu unsafe.Pointer, Buff C.int, Rcode *C.int, act *C.int) int {
  82. return int(C.XGC_BindParamByName(__pConn, Name, C.int(ArgType), C.int(Type),
  83. Valu, Buff, Rcode, act))
  84. }
  85. /*
  86. * Disconnect the database session connection established
  87. * by'C.XGC_OpenConn_Ips'.
  88. */
  89. func cgo_xgc_disconnect(__pConn *unsafe.Pointer) int {
  90. return int(C.XGC_CloseConn(__pConn))
  91. }
  92. // Prepare the executed SQL statement.
  93. func cgo_xgc_prepare(__pConn *unsafe.Pointer, query *C.char, prename *C.char) int {
  94. return int(C.XGC_Prepare2(__pConn, query, prename))
  95. }
  96. // Execute the SQL statement prepared by'C.XGC_Prepare2'.
  97. func cgo_xgc_execute(__pConn *unsafe.Pointer, prename *C.char,
  98. curname *C.char, res *unsafe.Pointer) int {
  99. return int(C.XGC_Execute2(__pConn, prename, curname, res))
  100. }
  101. // Cancel the SQL statement prepared by'C.XGC_Prepare2'.
  102. func cgo_xgc_unprepare(__pConn *unsafe.Pointer, prename *C.char) int {
  103. return int(C.XGC_UnPrepare(__pConn, prename))
  104. }
  105. // Close server cursor.
  106. func cgo_xgc_close_cursor(__pConn *unsafe.Pointer, curname *C.char) int {
  107. return int(C.XGC_CloseCursor(__pConn, curname))
  108. }
  109. // Receive the result set from the database server.
  110. func cgo_xgc_get_result_set(__pConn *unsafe.Pointer, pCT *C.int, pCC *C.int,
  111. pRC *C.int, pEC *C.int, pID *C.char) int {
  112. return int(C.XGC_getResultRet(__pConn, pCT, pCC, pRC, pEC, pID))
  113. }
  114. // Release result set.
  115. func cgo_xgc_free_rowset(__pRes *unsafe.Pointer) int {
  116. return int(C.XGC_FreeRowset(__pRes))
  117. }
  118. // Get data in the form of a cursor.
  119. func cgo_xgc_fetch_with_cursor(__pConn *unsafe.Pointer,
  120. curname *C.char, __pRes *unsafe.Pointer) int {
  121. return int(C.XGC_FetchServerCursorRowset(__pConn, curname, __pRes))
  122. }
  123. // Get the column name of the specified column.
  124. func cgo_xgc_get_column_name(__pRes *unsafe.Pointer, Seq int, cname *C.char) int {
  125. return int(C.XGC_getResultcolname(__pRes, C.int(Seq), cname))
  126. }
  127. // Get the number of fields in the current query.
  128. func cgo_xgc_get_fields_count(__pRes *unsafe.Pointer, CCnt *C.int) int {
  129. return int(C.XGC_getResultColumnsnum(__pRes, CCnt))
  130. }
  131. // Get the next row of result set data.
  132. func cgo_xgc_read_next(__pRes *unsafe.Pointer) int {
  133. return int(C.XGC_ReadNext(__pRes))
  134. }
  135. // Get the number of rows in the result set.
  136. func cgo_xgc_get_rows_count(__pRes *unsafe.Pointer, Rows *C.int) int {
  137. return int(C.XGC_getResultRecordnum(__pRes, Rows))
  138. }
  139. // Get the next result set.
  140. func cgo_xgc_next_result(__pRes *unsafe.Pointer) int {
  141. return int(C.XGC_NextResult(__pRes))
  142. }
  143. //
  144. func cgo_xgc_exec_with_cursor(__pConn *unsafe.Pointer, query *C.char,
  145. curname *C.char, __pRes *unsafe.Pointer, fields *C.int, rows *C.longlong, effects *C.int) int {
  146. return int(C.XGC_ExecwithServerCursorReader(__pConn, query, curname, __pRes, fields, rows, effects))
  147. }
  148. // Get the column data type of the specified column.
  149. func cgo_xgc_get_column_type(__pRes *unsafe.Pointer, Seq int, ColuType *C.int) int {
  150. return int(C.XGC_getResultcolType(__pRes, C.int(Seq), ColuType))
  151. }
  152. // Get the data of the specified column.
  153. func cgo_xgc_get_data(__pRes *unsafe.Pointer, Seq int, tartype int,
  154. pVal *C.char, Buff uint, act *C.int) int {
  155. return int(C.XGC_GetData(__pRes, C.int(Seq), C.int(tartype), unsafe.Pointer(pVal), C.int(Buff), act))
  156. }
  157. // Obtain large object data.
  158. func cgo_xgc_get_lob(__pRes *unsafe.Pointer, Seq int, tartype int,
  159. __pLob *unsafe.Pointer, Buff uint, act *C.int) int {
  160. return int(C.XGC_GetData(__pRes, C.int(Seq), C.int(tartype), unsafe.Pointer(__pLob), C.int(Buff), act))
  161. }
  162. // Create a large object data box.
  163. func cgo_xgc_new_lob(__pLob *unsafe.Pointer) int {
  164. return int(C.XGC_Create_Lob(__pLob))
  165. }
  166. // Obtain large object data.
  167. func cgo_xgc_get_lob_data(__pLob *unsafe.Pointer, pVal unsafe.Pointer, act C.int) int {
  168. return int(C.XGC_Get_Lob_data(__pLob, pVal, act))
  169. }
  170. // Obtain large object data.
  171. func cgo_xgc_put_lob_data(__pLob *unsafe.Pointer, pVal unsafe.Pointer, act int) int {
  172. return int(C.XGC_Put_Lob_data(__pLob, pVal, C.int(act)))
  173. }
  174. // Release large object data resources.
  175. func cgo_xgc_lob_distroy(__pLob *unsafe.Pointer) int {
  176. return int(C.XGC_Distroy_Lob(__pLob))
  177. }
  178. // Receive data from the database server.
  179. func cgo_xgc_exec_with_reader(__pConn *unsafe.Pointer, Sql *C.char,
  180. __pRes *unsafe.Pointer, fieldCount *C.int, rowCount *C.longlong, effectCount *C.int) int {
  181. return int(C.XGC_ExecwithDataReader(__pConn, Sql, __pRes, fieldCount, rowCount, effectCount))
  182. }
  183. /* }}*/