|
| 1 | +package main |
| 2 | + |
| 3 | +/* |
| 4 | +#include <stdint.h> |
| 5 | +#include <string.h> |
| 6 | +typedef signed char sdbyte; |
| 7 | +typedef unsigned char udbyte; |
| 8 | +typedef signed short sdint2; |
| 9 | +typedef unsigned short udint2; |
| 10 | +typedef signed int sdint4; |
| 11 | +typedef unsigned int udint4; |
| 12 | +typedef long long int sdint8; |
| 13 | +typedef unsigned long long int udint8; |
| 14 | +typedef sdint8 slength; |
| 15 | +typedef udint8 ulength; |
| 16 | +typedef void* dpointer; |
| 17 | +typedef sdint2 DPIRETURN; |
| 18 | +typedef void* dhandle; |
| 19 | +typedef dhandle dhenv; |
| 20 | +typedef dhandle dhcon; |
| 21 | +typedef dhandle dhstmt; |
| 22 | +typedef dhandle dhdesc; |
| 23 | +*/ |
| 24 | +import "C" |
| 25 | +import ( |
| 26 | + "fmt" |
| 27 | + "unsafe" |
| 28 | +) |
| 29 | + |
| 30 | +//export dpi_bind_param |
| 31 | +func dpi_bind_param(hstmt C.dhstmt, iparam C.udint2, paramType C.sdint2, |
| 32 | + ctype C.sdint2, dtype C.sdint2, precision C.ulength, |
| 33 | + scale C.sdint2, buf C.dpointer, bufLen C.slength, indPtr *C.slength) C.DPIRETURN { |
| 34 | + |
| 35 | + return dpi_bind_param2(hstmt, iparam, paramType, ctype, dtype, precision, scale, buf, bufLen, indPtr, nil) |
| 36 | +} |
| 37 | + |
| 38 | +//export dpi_bind_param2 |
| 39 | +func dpi_bind_param2(hstmt C.dhstmt, iparam C.udint2, paramType C.sdint2, |
| 40 | + ctype C.sdint2, dtype C.sdint2, precision C.ulength, |
| 41 | + scale C.sdint2, buf C.dpointer, bufLen C.slength, |
| 42 | + indPtr *C.slength, actLenPtr *C.slength) C.DPIRETURN { |
| 43 | + |
| 44 | + stmt, err := getStmtHandle(hstmt) |
| 45 | + if err != nil { |
| 46 | + return DSQL_INVALID_HANDLE |
| 47 | + } |
| 48 | + stmt.mu.Lock() |
| 49 | + defer stmt.mu.Unlock() |
| 50 | + |
| 51 | + idx := int(iparam) |
| 52 | + if idx < 1 { |
| 53 | + stmt.lastErr = &diagInfo{errorCode: -1, message: fmt.Sprintf("Invalid parameter index: %d", iparam)} |
| 54 | + return DSQL_ERROR |
| 55 | + } |
| 56 | + |
| 57 | + stmt.paramBindings[idx] = bindParamInfo{ |
| 58 | + paramType: int16(paramType), |
| 59 | + cType: int16(ctype), |
| 60 | + sqlType: int16(dtype), |
| 61 | + precision: uint64(precision), |
| 62 | + scale: int16(scale), |
| 63 | + dataPtr: unsafe.Pointer(buf), |
| 64 | + bufLen: int64(bufLen), |
| 65 | + indPtr: indPtr, |
| 66 | + actLenPtr: actLenPtr, |
| 67 | + } |
| 68 | + |
| 69 | + return DSQL_SUCCESS |
| 70 | +} |
| 71 | + |
| 72 | +//export dpi_number_params |
| 73 | +func dpi_number_params(hstmt C.dhstmt, paramCnt *C.udint2) C.DPIRETURN { |
| 74 | + stmt, err := getStmtHandle(hstmt) |
| 75 | + if err != nil { |
| 76 | + return DSQL_INVALID_HANDLE |
| 77 | + } |
| 78 | + stmt.mu.Lock() |
| 79 | + defer stmt.mu.Unlock() |
| 80 | + |
| 81 | + if paramCnt != nil { |
| 82 | + *paramCnt = C.udint2(stmt.paramCount) |
| 83 | + } |
| 84 | + return DSQL_SUCCESS |
| 85 | +} |
| 86 | + |
| 87 | +//export dpi_desc_param |
| 88 | +func dpi_desc_param(hstmt C.dhstmt, iparam C.udint2, |
| 89 | + sqlType *C.sdint2, prec *C.ulength, scale *C.sdint2, nullable *C.sdint2) C.DPIRETURN { |
| 90 | + |
| 91 | + stmt, err := getStmtHandle(hstmt) |
| 92 | + if err != nil { |
| 93 | + return DSQL_INVALID_HANDLE |
| 94 | + } |
| 95 | + stmt.mu.Lock() |
| 96 | + defer stmt.mu.Unlock() |
| 97 | + |
| 98 | + idx := int(iparam) - 1 |
| 99 | + if idx < 0 || idx >= len(stmt.params) { |
| 100 | + stmt.lastErr = &diagInfo{errorCode: -1, message: fmt.Sprintf("Parameter index %d out of range", iparam)} |
| 101 | + return DSQL_ERROR |
| 102 | + } |
| 103 | + |
| 104 | + p := &stmt.params[idx] |
| 105 | + if sqlType != nil { |
| 106 | + *sqlType = C.sdint2(p.sqlType) |
| 107 | + } |
| 108 | + if prec != nil { |
| 109 | + *prec = C.ulength(p.precision) |
| 110 | + } |
| 111 | + if scale != nil { |
| 112 | + *scale = C.sdint2(p.scale) |
| 113 | + } |
| 114 | + if nullable != nil { |
| 115 | + *nullable = C.sdint2(p.nullable) |
| 116 | + } |
| 117 | + |
| 118 | + return DSQL_SUCCESS |
| 119 | +} |
| 120 | + |
| 121 | +//export dpi_unbind_params |
| 122 | +func dpi_unbind_params(hstmt C.dhstmt) C.DPIRETURN { |
| 123 | + stmt, err := getStmtHandle(hstmt) |
| 124 | + if err != nil { |
| 125 | + return DSQL_INVALID_HANDLE |
| 126 | + } |
| 127 | + stmt.mu.Lock() |
| 128 | + defer stmt.mu.Unlock() |
| 129 | + |
| 130 | + stmt.paramBindings = make(map[int]bindParamInfo) |
| 131 | + return DSQL_SUCCESS |
| 132 | +} |
| 133 | + |
| 134 | +//export dpi_put_data |
| 135 | +func dpi_put_data(hstmt C.dhstmt, val C.dpointer, valLen C.slength) C.DPIRETURN { |
| 136 | + // data-at-exec: not fully implemented yet |
| 137 | + return DSQL_SUCCESS |
| 138 | +} |
| 139 | + |
| 140 | +//export dpi_param_data |
| 141 | +func dpi_param_data(hstmt C.dhstmt, valPtr *C.dpointer) C.DPIRETURN { |
| 142 | + // data-at-exec: not fully implemented yet |
| 143 | + return DSQL_NO_DATA |
| 144 | +} |
| 145 | + |
| 146 | +//export dpi_exec_add_batch |
| 147 | +func dpi_exec_add_batch(hstmt C.dhstmt) C.DPIRETURN { |
| 148 | + // Batch execution: placeholder |
| 149 | + return DSQL_SUCCESS |
| 150 | +} |
| 151 | + |
| 152 | +//export dpi_exec_batch |
| 153 | +func dpi_exec_batch(hstmt C.dhstmt) C.DPIRETURN { |
| 154 | + // Batch execution: placeholder |
| 155 | + return DSQL_SUCCESS |
| 156 | +} |
0 commit comments