/
SQLStatement.prg
1093 lines (691 loc) · 22 KB
/
SQLStatement.prg
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/// <include file="SQL.xml" path="doc/SQLStatement/*" />
CLASS SQLStatement
HIDDEN hStmt AS PTR
HIDDEN cStatement AS STRING
HIDDEN oConn AS SQLConnection
HIDDEN oErrInfo AS SQLErrorInfo
HIDDEN lPrepFlag AS LOGIC
HIDDEN aParams[0] AS ARRAY
PROTECT nRowSet AS INT
HIDDEN nCursorType AS INT
HIDDEN nSimulateCursor AS INT
PROTECT nKeySet AS INT
// HIDDEN nRecCount AS LONGINT // Unused
PROTECT aUserOption AS ARRAY
/// <exclude />
METHOD __AllocStmt() AS LOGIC STRICT
LOCAL hStmtNew AS PTR
LOCAL nRetCode AS INT
LOCAL lRet AS LOGIC
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:__AllocStmt()" )
#ENDIF
IF hStmt = SQL_NULL_HSTMT
//RvdH 050413 This should be replaced with SqlAllocHandle
nRetCode := SQLAllocStmt( oConn:ConnHandle, @hStmtNew )
IF nRetCode = SQL_SUCCESS
oErrInfo:ErrorFlag := FALSE
SELF:hStmt := hStmtNew
#IFDEF __DEBUG__
__SQLOutputDebug( "** hDbc="+AsString( oConn:ConnHandle )+", hStmt="+AsString( hStmt ) )
#ENDIF
oConn:__RegisterStmt( SELF )
lRet := TRUE
ELSE
SELF:MakeErrorInfo(SELF, #AllocStmt, nRetCode)
ENDIF
ELSE
// Statement already allocated
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__STMT_ALLOC ), #AllocStmt )
ENDIF
RETURN lRet
/// <exclude />
METHOD __FreeParameters()
LOCAL nPar AS DWORD
LOCAL oPar AS SqlParameter
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:Axit(), hStmt = "+AsString( hStmt ) )
#ENDIF
IF ! SELF:__FreeStmt(SQL_RESET_PARAMS)
RETURN FALSE
ENDIF
// Destroy 'Our' Parameter objects
FOR nPar := 1 TO ALen(SELF:aParams)
IF (IsInstanceOfUsual(aParams[nPar], #SQLParameter))
oPar := aParams[nPar]
IF oPar:InternalParam
oPar:Destroy()
ENDIF
ENDIF
NEXT
ASize(SELF:aParams,0)
RETURN TRUE
/// <exclude />
METHOD __FreeStmt( nOption AS WORD) AS LOGIC STRICT
LOCAL nRetCode AS INT
LOCAL lRet AS LOGIC
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:__FreeStmt( "+AsString( nOption )+" ) hStmt="+AsString( hStmt ) )
#ENDIF
IF hStmt != SQL_NULL_HSTMT
IF nOption = SQL_DROP
SQLFreeStmt( hStmt, SQL_UNBIND )
nRetCode := SQLFreeStmt( hStmt, SQL_CLOSE )
//RvdH 050413 This should be replaced with a Call to SQLFreeHandle()
nRetCode := SQLFreeStmt( hStmt, SQL_DROP )
ELSE
nRetCode := SQLFreeStmt( hStmt, nOption )
ENDIF
IF nRetCode = SQL_SUCCESS
oErrInfo:ErrorFlag := FALSE
IF nOption = SQL_DROP
SELF:oConn:__UnRegisterStmt( SELF )
SELF:hStmt := SQL_NULL_HSTMT
lPrepFlag := FALSE
ELSEIF nOption = SQL_CLOSE
lPrepFlag := FALSE
ENDIF
lRet := TRUE
ELSE
SELF:MakeErrorInfo(SELF, #FreeStmt, nRetCode)
ENDIF
ENDIF
RETURN lRet
/// <exclude />
METHOD __GenerateSQLError( cErrorString AS STRING, symMethod AS SYMBOL) AS SQLErrorInfo STRICT
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:__GenerateSQLError( "+ ;
AsString( cErrorString )+","+AsString( symMethod )+" )" )
#ENDIF
oErrInfo:ErrorMessage := __CavoStr( __CAVOSTR_SQLCLASS__ODBC_VO ) + ;
Symbol2String( ClassName( SELF ) ) + ;
":" + Symbol2String( symMethod ) + ;
" " + cErrorString
oErrInfo:NativeError:= 0
oErrInfo:SQLState := __CavoStr( __CAVOSTR_SQLCLASS__GENERAL_ERR )
oErrInfo:ErrorFlag := TRUE
oErrInfo:SubSystem := __CavoStr( __CAVOSTR_SQLCLASS_SUBSYS )
oErrInfo:MethodSelf := SELF
oErrInfo:FuncSym := symMethod
oErrInfo:CallFuncSym:= symMethod
oErrInfo:Severity := ES_ERROR
oErrInfo:ReturnCode := SQL_SUCCESS
RETURN oErrInfo
/// <exclude />
ACCESS __Params AS ARRAY STRICT
RETURN SELF:aParams
/// <exclude />
ASSIGN __Params( aNewParams AS ARRAY) STRICT
RETURN
/// <exclude />
METHOD __Reset( ) AS LOGIC STRICT
LOCAL lRet AS LOGIC
IF hStmt != SQL_NULL_HSTMT
IF SELF:__FreeStmt( SQL_CLOSE )
lRet := SELF:Execute()
ENDIF
ENDIF
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:__ResetStmt() returns " + AsString( lRet ) )
#ENDIF
RETURN lRet
/// <exclude />
METHOD __SetDefaultStatementOptions() AS LOGIC STRICT
LOCAL n AS INT
IF SELF:nCursorType > 0
n := SELF:nCursorType
SELF:SetStatementOption( SQL_CURSOR_TYPE, n , TRUE)
ENDIF
// If keyset driven, set keyset size
IF ( SELF:nCursorType == SQL_CURSOR_KEYSET_DRIVEN )
IF SELF:nKeySet > 0
n := SELF:nKeySet
SELF:SetStatementOption( SQL_KEYSET_SIZE, n , TRUE)
ENDIF
ENDIF
IF SELF:nRowSet > 0
n := SELF:nRowSet
SELF:SetStatementOption( SQL_ROWSET_SIZE, n , TRUE)
ENDIF
// Set concurrency level
n := SELF:ScrollConcurrency
IF n > 0
SELF:SetStatementOption( SQL_CONCURRENCY, n , TRUE)
ENDIF
RETURN TRUE
/// <exclude />
METHOD __SetParameters( aNewParams AS ARRAY) AS LOGIC STRICT
LOCAL nIndex AS DWORD
LOCAL nNumParams AS DWORD
LOCAL nRetCode AS INT
LOCAL uParam AS USUAL
LOCAL oParam AS SqlParameter
IF ( ! SELF:__FreeStmt( SQL_RESET_PARAMS ) )
RETURN FALSE
ENDIF
nNumParams := ALen( aNewParams )
ASize(SELF:aParams, nNumParams)
FOR nIndex := 1 UPTO nNumParams
uParam := aNewParams[nIndex]
IF IsInstanceOfUsual(uParam, #SqlParameter)
oParam := uParam
// Do not set the 'internalparam' flag
ELSE
oParam := SqlParameter{uParam}
oParam:InternalParam := TRUE
ENDIF
SELF:aParams[nIndex] := oParam
nRetCode := oParam:bind(SELF, nIndex)
IF ( nRetCode != SQL_SUCCESS )
SELF:MakeErrorInfo(SELF, #SetParameters, nRetCode)
RETURN FALSE
ENDIF
NEXT
SELF:__ErrInfo:ErrorFlag := FALSE
RETURN TRUE
/// <exclude />
METHOD __SetScrollOptions( nConcType AS DWORD, nKeySet AS DWORD, lAsync AS LOGIC) AS LOGIC STRICT
LOCAL lRet AS LOGIC
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:SetScrollOptions()" )
#ENDIF
lRet := TRUE
lRet := SELF:SetStatementOption( SQL_CURSOR_TYPE, nKeySet, .F. )
IF lRet
lRet := SELF:SetStatementOption( SQL_CONCURRENCY, nConcType, .F. )
ENDIF
IF lRet
lRet := SELF:SetStatementOption( SQL_ROWSET_SIZE, SELF:nRowSet, .F. )
ENDIF
IF lRet
lRet := SELF:SetStatementOption( SQL_ASYNC_ENABLE, IIF( lAsync, 1, 0 ), .F. )
ENDIF
IF lRet
oErrInfo:ErrorFlag := FALSE
ELSE
SELF:MakeErrorInfo(SELF, #__SetScrollOptions,0)
ENDIF
RETURN lRet
/// <include file="SQL.xml" path="doc/SQLStatement.dtor/*" />
DESTRUCTOR()
SELF:Destroy()
RETURN
/// <include file="SQL.xml" path="doc/SQLStatement.Commit/*" />
METHOD Commit()
//
// UH: Obsolete method, don't support after 2.0 !!!!
//
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:Commit()" )
#ENDIF
RETURN SELF:__Connection:Commit()
/// <exclude />
ACCESS __Connection as SqlConnection
RETURN SELF:oConn
/// <include file="SQL.xml" path="doc/SQLStatement.Connection/*" />
ACCESS Connection
RETURN SELF:oConn
/// <include file="SQL.xml" path="doc/SQLStatement.CursorType/*" />
ACCESS CursorType
RETURN SELF:GetStatementOption( SQL_CURSOR_TYPE )
/// <include file="SQL.xml" path="doc/SQLStatement.CursorType/*" />
ASSIGN CursorType( nVal )
IF IsNumeric( nVal ) .AND. ;
( nVal == SQL_CURSOR_FORWARD_ONLY .OR. ;
nVal == SQL_CURSOR_KEYSET_DRIVEN .OR. ;
nVal == SQL_CURSOR_DYNAMIC .OR. ;
nVal == SQL_CURSOR_STATIC )
RETURN SELF:nCursorType := nVal
ENDIF
RETURN SELF:nCursorType
/// <include file="SQL.xml" path="doc/SQLStatement.Destroy/*" />
METHOD Destroy() AS USUAL CLIPPER
IF hStmt != SQL_NULL_HSTMT .AND. oConn != NULL_OBJECT
IF oConn:Connected
SELF:__FreeParameters()
SELF:__FreeStmt( SQL_DROP )
//IF ! InCollect()
SELF:hStmt := SQL_NULL_HSTMT
UnregisterAxit(SELF)
//ENDIF
ENDIF
ENDIF
RETURN NIL
/// <exclude />
ACCESS __ErrInfo as SqlErrorInfo
return oErrInfo
/// <include file="SQL.xml" path="doc/SQLStatement.ErrInfo/*" />
ACCESS ErrInfo
RETURN oErrInfo
/// <include file="SQL.xml" path="doc/SQLStatement.ErrInfo/*" />
ASSIGN ErrInfo( uVal )
SELF:oErrInfo := uVal
RETURN SELF:oErrInfo
/// <include file="SQL.xml" path="doc/SQLStatement.Execute/*" />
METHOD Execute( uParm )
LOCAL nCount AS DWORD
LOCAL aArg AS ARRAY
LOCAL nRetCode AS INT
LOCAL l AS LONGINT
LOCAL lRet AS LOGIC
LOCAL lNewParams AS LOGIC
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:Execute()" )
#ENDIF
IF hStmt = SQL_NULL_HSTMT
SELF:__AllocStmt()
ENDIF
nCount := ALen( SELF:aParams )
IF PCount() != 0
IF PCount() = 1 .AND. UsualType( uParm ) = ARRAY
aArg := uParm
nCount := ALen( uParm )
ELSE
aArg := {}
FOR nCount := 1 UPTO PCount()
AAdd( aArg, _GETMPARAM( nCount ) )
NEXT
ENDIF
lNewParams := TRUE
ENDIF
IF nCount != 0
IF ! lNewParams
aArg := SELF:aParams
ENDIF
IF !SELF:__SetParameters( aArg )
SELF:__FreeParameters()
RETURN FALSE
ENDIF
ENDIF
IF ALen(SELF:aParams) > 0 .AND. ! lPrepFlag
SELF:Prepare()
ENDIF
IF !lPrepFlag
IF !SELF:__SetDefaultStatementOptions()
IF !( oErrInfo:SQLState = __CavoStr( __CAVOSTR_SQLCLASS__FUNCSEQ_ERR ) )
SELF:oConn:ScrollCsr := FALSE
ENDIF
ENDIF
l := LONGINT( _CAST,SLen( cStatement ) )
#IFDEF __DEBUG__
IF DWORD( _CAST, l ) != PszLen( String2Psz( cStatement ) )
__SQLOutputDebug( "** STATEMENT CONTAINS embedded ZERORs" )
// "Embedded zeros found"
MemoWrit( "c:\sqlstat.log", cStatement )
ENDIF
__SQLOutputDebug( "** MemTotal() -> " + NTrim( MemTotal() ) )
#ENDIF
//_DebOut32(String2Psz("SQLExecDirect start "+NTrim(Seconds())))
IF l > 0
nRetCode := SQLExecDirect( hStmt, String2Psz( cStatement ), l )
ENDIF
//_DebOut32(String2Psz("SQLExecDirect ok "+NTrim(Seconds())))
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLExecDirect()" )
__SQLOutputDebug( "** MemTotal() -> " + NTrim( MemTotal() ) )
#ENDIF
ELSE
//_DebOut32(String2Psz("SQLExecute start "+NTrim(Seconds())))
nRetCode := SQLExecute( hStmt )
//_DebOut32(String2Psz("SQLExecute ok "+NTrim(Seconds())))
ENDIF
// SQL_SUCCESS_WITH_INFO is no error
// We should still check the results here though,
// I have refrained from doing this here to keep the
// changes small.
IF nRetCode = SQL_SUCCESS .OR. nRetCode = SQL_SUCCESS_WITH_INFO
lPrepFlag := TRUE
lRet := TRUE
// Try to determine the number of rows
// SQLRowCount is only guaranteed to work after UPDATE,
// INSERT or DELETE operations. Some drivers however
// may also be able to return the number of rows
// of a SELECT statement even before fetching any rows.
// So this is still worth a try.
ELSE
SELF:MakeErrorInfo(SELF, #Execute, nRetCode)
ENDIF
#IFDEF __DEBUG__
__SQLOutputDebug( "**** returns : " + AsString( lRet ) )
#ENDIF
//SELF:__FreeParameters()
RETURN lRet
/// <include file="SQL.xml" path="doc/SQLStatement.FreeStmt/*" />
METHOD FreeStmt( fOption )
//RvdH 070530 Added default value, as suggested by Stavros Spanos
IF PCount() == 0
fOption := SQL_CLOSE
ENDIF
RETURN SELF:__FreeStmt( fOption )
/// <include file="SQL.xml" path="doc/SQLStatement.GetStatementOption/*" />
METHOD GetStatementOption( fOption )
LOCAL nValue AS INT
LOCAL pData AS PTR
LOCAL nRetCode AS INT
LOCAL xRet AS USUAL
//
// Get current setting for a statement option; returns NIL if err
//
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:GetStatementOption()" )
#ENDIF
IF hStmt != SQL_NULL_HSTMT
pData := @nValue
//RvdH 050413 This should be replaced with a Call to SQLGetStmtAttr()
nRetCode := SQLGetStmtOption( hStmt, fOption, pData )
IF nRetCode = SQL_SUCCESS
oErrInfo:ErrorFlag := FALSE
xRet := nValue
ELSE
SELF:MakeErrorInfo(SELF,#GetStatementOption, nRetCode)
ENDIF
ELSE
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__NO_STMT ), #GetStatementOption )
ENDIF
RETURN xRet
/// <include file="SQL.xml" path="doc/SQLStatement.HyperLabel/*" />
ACCESS HyperLabel
LOCAL oHL AS HyperLabel
oHL := HyperLabel{ #Statement, ;
cStatement, ;
Symbol2String( ClassName( SELF ) )+ ": " + cStatement, ;
Symbol2String( ClassName( SELF ) )+ "_" + cStatement }
RETURN oHL
/// <include file="SQL.xml" path="doc/SQLStatement.ctor/*" />
CONSTRUCTOR( cSQLStatement, oSQLConnection )
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:Init( "+AsString( cSQLStatement )+" )" )
#ENDIF
lPrepFlag := FALSE
// Filled in with the number of rows affected by the next SQLExecDirect call.
oErrInfo := SQLErrorInfo{}
IF IsString( cSQLStatement ) .AND. SLen( cSQLStatement ) > 0
SELF:cStatement := cSQLStatement
ENDIF
IF oSQLConnection = NIL
SELF:oConn := SQLSetConnection()
ELSE
SELF:oConn := oSQLConnection
ENDIF
SELF:ScrollConcurrency := SqlSetStmtConcurrency()
SELF:CursorType := SqlSetStmtCursorType()
SELF:SimulateCursor := SqlSetStmtSimulateCursor()
IF oConn:Connected
SELF:__AllocStmt()
ELSE
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__NOT_CONN ), #Init )
ENDIF
nRowSet := 1
nKeySet := 128
SELF:aUserOption := {}
SELF:aParams := {}
RETURN
/// <include file="SQL.xml" path="doc/SQLStatement.KeySet/*" />
ACCESS KeySet
RETURN SELF:nKeySet
/// <include file="SQL.xml" path="doc/SQLStatement.KeySet/*" />
ASSIGN KeySet( n )
IF IsNumeric( n )
SELF:nKeySet := Integer( n )
ENDIF
RETURN SELF:nKeySet
/// <include file="SQL.xml" path="doc/SQLStatement.MakeErrorInfo/*" />
METHOD MakeErrorInfo(oObject, symMethod, nRetCode)
SELF:ErrInfo := SQLErrorInfo{ oObject, symMethod, ;
SELF:oConn:EnvHandle, ;
SELF:oConn:ConnHandle, ;
SELF:hStmt }
SELF:__ErrInfo:ReturnCode := nRetCode
RETURN SELF:ErrInfo
/// <include file="SQL.xml" path="doc/SQLStatement.NativeSQL/*" />
ACCESS NativeSQL
LOCAL nBytes AS INT // dcaton 070206 was DWORD
LOCAL nSize AS DWORD
LOCAL cValueNew AS STRING
LOCAL nRetCode AS INT
LOCAL pszStmt AS PSZ
IF cStatement == NULL_STRING .OR. hStmt = SQL_NULL_HSTMT
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__NO_STMT ), #NativeSQL )
ELSE
nSize := SLen( cStatement ) * 2 + 1
pszStmt := MemAlloc( nSize )
IF pszStmt == NULL_PSZ
SQLThrowOutOfMemoryError()
nRetCode := SQL_ERROR
ELSE
nRetCode := SQLNativeSql( oConn:ConnHandle, ;
String2Psz( cStatement ), ;
_SLen( cStatement ) , ;
pszStmt, ;
SHORTINT( _CAST,nSize - 1 ), ;
@nBytes )
ENDIF
IF nRetCode = SQL_SUCCESS
oErrInfo:ErrorFlag := FALSE
cValueNew := Psz2String( pszStmt )
ELSE
SELF:MakeErrorInfo(SELF, #NativeSql, nRetCode)
ENDIF
MemFree( pszStmt )
ENDIF
RETURN cValueNew
/// <include file="SQL.xml" path="doc/SQLStatement.NumParameters/*" />
ACCESS NumParameters
LOCAL nCount AS SHORTINT // dcaton 070206 was INT
LOCAL nRetCode AS INT
IF ( hStmt = SQL_NULL_HSTMT )
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__NO_STMT ), #NumParameters )
nCount := -1
ELSE
nRetCode := SQLNumParams( hStmt, @nCount )
IF nRetCode = SQL_SUCCESS
oErrInfo:ErrorFlag := FALSE
ELSE
SELF:MakeErrorInfo(SELF, #NumParameters, nRetCode)
nCount := -1
ENDIF
ENDIF
RETURN nCount
/// <include file="SQL.xml" path="doc/SQLStatement.NumSuccessfulRows/*" />
ACCESS NumSuccessfulRows
LOCAL nCount AS INT
LOCAL nRetCode AS INT
IF hStmt = SQL_NULL_HSTMT
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__NO_STMT ), #NumSuccessfulRows )
nCount := -1
ELSE
nRetCode := SQLRowCount( hStmt, @nCount )
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLRowCount() returns " + NTrim( nRetCode ) )
__SQLOutputDebug( "** Number of rows " + NTrim( nCount ) )
#ENDIF
IF nRetCode = SQL_SUCCESS
oErrInfo:ErrorFlag := FALSE
ELSE
SELF:MakeErrorInfo(SELF,#NumSuccessfulRows, nRetCode)
nCount := -1
ENDIF
ENDIF
RETURN nCount
/// <include file="SQL.xml" path="doc/SQLStatement.Prepare/*" />
METHOD Prepare()
LOCAL nRetCode AS INT
LOCAL lRet AS LOGIC
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:Prepare()" )
#ENDIF
IF hStmt = SQL_NULL_HSTMT
IF !SELF:__AllocStmt()
RETURN lRet
ENDIF
ENDIF
IF SELF:oConn:ScrollCsr
// Set all required options
IF !SELF:__SetDefaultStatementOptions()
IF !( oErrInfo:SQLState = __CavoStr( __CAVOSTR_SQLCLASS__FUNCSEQ_ERR ) )
SELF:oConn:ScrollCsr := FALSE
ENDIF
ENDIF
ENDIF
nRetCode := SQLPrepare( hStmt, String2Psz( cStatement ), LONGINT( _CAST, SLen( cStatement ) ) )
///RvdH
// SQL_SUCCESS_WITH_INFO is no error
// We should still check the results here though,
// I have refrained from doing this here to keep the
// changes small.
IF nRetCode = SQL_SUCCESS .OR. nRetCode = SQL_SUCCESS_WITH_INFO
oErrInfo:ErrorFlag := FALSE
lPrepFlag := TRUE
lRet := TRUE
ELSE
SELF:MakeErrorInfo(SELF, #Prepare, nRetCode)
ENDIF
RETURN lRet
/// <include file="SQL.xml" path="doc/SQLStatement.PrepFlag/*" />
ACCESS PrepFlag
RETURN SELF:lPrepFlag
/// <include file="SQL.xml" path="doc/SQLStatement.PrepFlag/*" />
ASSIGN PrepFlag( lNew )
IF IsLogic( lNew )
SELF:lPrepFlag := lNew
ENDIF
RETURN SELF:lPrepFlag
/// <include file="SQL.xml" path="doc/SQLStatement.RecCount/*" />
ACCESS RecCount
RETURN SELF:NumSuccessfulRows
/// <include file="SQL.xml" path="doc/SQLStatement.RollBack/*" />
METHOD RollBack()
//
// UH: Obsolete method, don't support after 2.0 !!!!
//
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:Rollback()" )
#ENDIF
RETURN SELF:__Connection:RollBack()
/// <include file="SQL.xml" path="doc/SQLStatement.RowSet/*" />
ACCESS RowSet
RETURN SELF:nRowSet
/// <include file="SQL.xml" path="doc/SQLStatement.RowSet/*" />
ASSIGN RowSet( nVal )
IF IsNumeric( nVal ) .AND. nVal > 0
// UH: To implement buffering for scrollable cursors
// SELF:nRowSet := nVal
SELF:nRowSet := 1
ENDIF
RETURN SELF:nRowSet
/// <include file="SQL.xml" path="doc/SQLStatement.ScrollConcurrency/*" />
ACCESS ScrollConcurrency
RETURN SELF:oConn:ScrollConcurrency
/// <include file="SQL.xml" path="doc/SQLStatement.ScrollConcurrency/*" />
ASSIGN ScrollConcurrency( nVal )
RETURN SELF:oConn:ScrollConcurrency := nVal
/// <include file="SQL.xml" path="doc/SQLStatement.SetStatementOption/*" />
METHOD SetStatementOption( fOption, uValue, lUser )
//
// Sets current setting for a statement option; returns TRUE if successful
//
LOCAL nRetCode AS INT
LOCAL nExist AS DWORD
LOCAL lRet AS LOGIC
LOCAL nOption AS DWORD
#IFDEF __DEBUG__
__SQLOutputDebug( "** SQLStatement:SetStatementOption( " + ;
AsString( fOption ) + "," + AsString( uValue ) + " )" )
#ENDIF
DEFAULT( @lUser, TRUE )
nExist := AScan( SELF:aUserOption, fOption )
IF lUser
IF nExist = 0
AAdd( aUserOption, fOption )
ENDIF
ELSE
IF nExist > 0
//
// Don't overwrite option set by user
//
RETURN FALSE
ENDIF
ENDIF
IF hStmt = SQL_NULL_HSTMT
SELF:__GenerateSQLError( __CavoStr( __CAVOSTR_SQLCLASS__NO_STMT ), #SetStatementOption )
ELSE
//RvdH 050413 This should be replaced with a Call to SQLSetStmtAttr()
nOption := uValue
nRetCode := SQLSetStmtOption( hStmt, fOption, nOption )
#IFDEF __DEBUG__
__SQLOutputDebug( "** nRetCode : " + NTrim( nRetCode ) )
#ENDIF
IF ( nRetCode = SQL_SUCCESS ) .OR. ( nRetCode = SQL_SUCCESS_WITH_INFO )
oErrInfo:ErrorFlag := FALSE
lRet := TRUE
ELSE
SELF:MakeErrorInfo(SELF, #SetStatementOption, nRetCode)
ENDIF
ENDIF
RETURN lRet
/// <include file="SQL.xml" path="doc/SQLStatement.SimulateCursor/*" />
ACCESS SimulateCursor
RETURN SELF:GetStatementOption( SQL_SIMULATE_CURSOR )
/// <include file="SQL.xml" path="doc/SQLStatement.SimulateCursor/*" />
ASSIGN SimulateCursor( nVal )
IF IsNumeric( nVal ) .AND. ;
( nVal == SQL_SC_NON_UNIQUE .OR. ;
nVal == SQL_SC_TRY_UNIQUE .OR. ;
nVal == SQL_SC_UNIQUE )
RETURN SELF:nSimulateCursor := nVal
ENDIF