I forgot the attach the code: HB_FUNC( SQLEXECBIND ) { int nParam; int nNumParams = hb_pcount();
SQLRETURN retcode; SQLHSTMT hstmt = ( HSTMT ) hb_parptr( 1 ); LPTSTR szQuery = hb_parcx( 2 ); retcode = SQLPrepare(hstmt, szQuery, SQL_NTS); for(nParam = 3; nParam <= nNumParams; nParam++) { PHB_ITEM pItem = hb_param( nParam, HB_IT_ANY ); if (HB_IS_INTEGER(pItem)) { SQLINTEGER pValue = hb_parni(nParam); SQLINTEGER cbValue = 0; retcode = SQLBindParameter(hstmt, nParam - 2, SQL_PARAM_INPUT, SQL_C_USHORT, SQL_INTEGER, 0, 0, &pValue, 0, &cbValue); } else if (HB_IS_DOUBLE(pItem)) { SQLDOUBLE pValue = hb_parnd(nParam); SQLINTEGER cbValue = 0; retcode = SQLBindParameter(hstmt, nParam - 2, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_DOUBLE, 0, 0, &pValue, 0, &cbValue); } else if (HB_IS_LOGICAL(pItem)) { SQLINTEGER pValue = hb_parl(nParam); SQLINTEGER cbValue = 0; retcode = SQLBindParameter(hstmt, nParam - 2, SQL_PARAM_INPUT, SQL_C_USHORT, SQL_INTEGER, 0, 0, &pValue, 0, &cbValue); } else if (HB_IS_STRING(pItem) || HB_IS_NIL(pItem)) { LPTSTR pValue = hb_parcx(nParam); SQLINTEGER cbValue = SQL_NTS; retcode = SQLBindParameter(hstmt, nParam - 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, hb_parclen(nParam), 0, pValue, 0, &cbValue); } else if (HB_IS_DATE(pItem)) { SQL_DATE_STRUCT pValue; SQLINTEGER cbValue = 0; int year, month, day; hb_dateDecode( hb_itemGetDL( pItem ), &year, &month, &day ); pValue.year = year; pValue.month = month; pValue.day = day; retcode = SQLBindParameter(hstmt, nParam - 2, SQL_PARAM_INPUT, SQL_C_TYPE_DATE, SQL_TYPE_DATE, 0, 0, &pValue, 0, &cbValue); } } retcode = SQLExecute(hstmt); hb_retni(retcode); } On Tue, Aug 26, 2008 at 3:33 PM, Rodrigo Miguel <[EMAIL PROTECTED]> wrote: > Hi All, > > I wrote a small workaround of SQLBindParameter and I need some help about > the approach to be used. The code can be found at the end of this email. So > if I execute the following line: > > Approach 1 > ========== > > SQLExecBind( hStmt, 'INSERT INTO test_rod(CustomerID, EmployeeID, Salary, > OrderDate) VALUES (?, ?, ?, ?)', 3, 'RODRIGO', 8000, date() ) > > insted of have these values as: > > 3, "RODRIGO", 8000, "2008-08-18" > > I got > > 8000, "RODRIGO", 8000, "2008-08-18" > > Anyway, I was able to figure out the issue, and that's being caused by > reuse of pointers of the same C type values. So I was wondering how to > resolve that. Shall I use an array of pointers? or shall I use hb_xgrab and > then let the GC clear that after the execution of SQLExecute? > > Or should I separate that in 3 formal functions as showed below: > > Approach 2 > ========== > > a := 0 > b := '' > c := Ctod('') > > res := SQLPrepare(hstmt, 'INSERT INTO test_rod(CustomerID, EmployeeID, > OrderDate) VALUES (?, ?, ?)') > > res := SQLBindParameter(hstmt, 1, @a) > res := SQLBindParameter(hstmt, 2, @b) > res := SQLBindParameter(hstmt, 3, @c) > > for i := 1 to 1000000 > a := i > b := 'TEST' + str(i) > c := Date() + 1 > res := SQLExecute(hstmt) > next > > So, the second way if my prefered one, but the problem is, how the > reference inside of HB_FUNC the variables (a, b and c) until the execution > of next SQLExecute() ? Is that possible? The code showed above is that we > usually do in a C code, Prepare and bind once and then execute many times as > requested the SQLExecute. > > Suggestions and comments? > > Thanks in advance. > Rodrigo Moreno > >
_______________________________________________ Harbour mailing list Harbour@harbour-project.org http://lists.harbour-project.org/mailman/listinfo/harbour