1 /**
2 Copyright (C) 1995, 1996 by Ke Jin <kejin@visigenic.com>
3 Enhanced for unixODBC (1999) by Peter Harvey <pharvey@codebydesign.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 **/
15 #include <config.h>
16 #include "driver.h"
17
SQLParamData(HSTMT hstmt,PTR * prgbValue)18 RETCODE SQL_API SQLParamData(
19 HSTMT hstmt,
20 PTR* prgbValue)
21 {
22 stmt_t* pstmt = hstmt;
23 int ipar;
24 param_t* ppar;
25 fptr_t cvt;
26 char* data;
27 date_t dt;
28
29 UNSET_ERROR( pstmt->herr );
30
31 ipar = pstmt->putipar;
32 ppar = pstmt->ppar + ipar - 1;
33
34 if ( ipar )
35 {
36 ppar->need = 0;
37 pstmt->ndelay --;
38
39 if ( ppar->ctype == SQL_C_CHAR )
40 {
41 if ( ! ppar->putdtbuf && ! ppar->putdtlen )
42 data = 0;
43 else
44 {
45 cvt = ppar->cvt;
46 data= cvt(ppar->putdtbuf, ppar->putdtlen, &dt);
47 }
48
49 MEM_FREE( ppar->putdtbuf );
50 ppar->putdtbuf = 0;
51 ppar->putdtlen = 0;
52
53 if ( data == (char*)(-1) )
54 {
55 PUSHSQLERR( pstmt->herr, en_S1000 );
56
57 return SQL_ERROR;
58 }
59
60 sqlputdata( pstmt, ipar, data );
61 }
62 }
63
64 if ( pstmt->ndelay )
65 {
66 for (ipar++, ppar++;;)
67 {
68 if ( ppar->need )
69 {
70 *prgbValue = (PTR)(ppar->userbuf);
71 pstmt->putipar = ipar;
72
73 return SQL_NEED_DATA;
74 }
75 }
76 }
77
78 if ( nnsql_execute(pstmt->yystmt) )
79 {
80 int code;
81
82 code = nnsql_errcode( pstmt->yystmt );
83
84 if ( code == -1 )
85 code = errno;
86
87 PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt));
88
89 return SQL_ERROR;
90 }
91
92 if ( ! nnsql_getcolnum(pstmt->yystmt)
93 && nnsql_getrowcount(pstmt->yystmt) > 1 )
94 {
95 PUSHSQLERR( pstmt->herr, en_01S04);
96
97 return SQL_SUCCESS_WITH_INFO;
98 }
99
100 return SQL_SUCCESS;
101 }
102
103