File: SQLParamData.c

package info (click to toggle)
unixodbc 2.3.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,524 kB
  • ctags: 7,656
  • sloc: ansic: 89,405; sh: 15,975; makefile: 1,574; yacc: 969; sql: 1
file content (102 lines) | stat: -rwxr-xr-x 2,040 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
    Copyright (C) 1995, 1996 by Ke Jin <kejin@visigenic.com>
	Enhanced for unixODBC (1999) by Peter Harvey <pharvey@codebydesign.com>
	
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
**/
#include <config.h>
#include "driver.h"

RETCODE SQL_API SQLParamData(
									 HSTMT hstmt,
									 PTR*  prgbValue)
{
	stmt_t*  pstmt = hstmt;
	int      ipar;
	param_t* ppar;
	fptr_t      cvt;
	char*    data;
	date_t      dt;

	UNSET_ERROR( pstmt->herr );

	ipar = pstmt->putipar;
	ppar = pstmt->ppar + ipar - 1;

	if ( ipar )
	{
		ppar->need = 0;
		pstmt->ndelay --;

		if ( ppar->ctype == SQL_C_CHAR )
		{
			if ( ! ppar->putdtbuf && ! ppar->putdtlen )
				data = 0;
			else
			{
				cvt = ppar->cvt;
				data= cvt(ppar->putdtbuf, ppar->putdtlen, &dt);
			}

			MEM_FREE( ppar->putdtbuf );
			ppar->putdtbuf = 0;
			ppar->putdtlen = 0;

			if ( data == (char*)(-1) )
			{
				PUSHSQLERR( pstmt->herr, en_S1000 );

				return SQL_ERROR;
			}

			sqlputdata( pstmt, ipar, data );
		}
	}

	if ( pstmt->ndelay )
	{
		for (ipar++, ppar++;;)
		{
			if ( ppar->need )
			{
				*prgbValue = (PTR)(ppar->userbuf);
				pstmt->putipar = ipar;

				return SQL_NEED_DATA;
			}
		}
	}

	if ( nnsql_execute(pstmt->yystmt) )
	{
		int   code;

		code = nnsql_errcode( pstmt->yystmt );

		if ( code == -1 )
			code = errno;

		PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt));

		return SQL_ERROR;
	}

	if ( ! nnsql_getcolnum(pstmt->yystmt)
		  && nnsql_getrowcount(pstmt->yystmt) > 1 )
	{
		PUSHSQLERR( pstmt->herr, en_01S04);

		return SQL_SUCCESS_WITH_INFO;
	}

	return SQL_SUCCESS;
}