> > gObjtSQLcommand = "Select Count(*) as Records From " + IIf (Empty (cTable_Owner), "", cTable_Owner + ".") + cTable_Name > > If SqlExec (gSQLHandle, gObjtSQLcommand, "SQLcurCount") <> 1 > If Used ("SQLcurCount") > Use In SQLcurCount > endif > Messagebox ("Unexpected SqlExec () error. Browse will not be executed. Sorry.", (0+16+0), cCaption) > Return > endif > > Select SQLcurCount > > If VarType (Records) = "C" && This is because some servers return numeric and others return character > nRecCount = Val (Records) > else > nRecCount = Records > endif > > If nRecCount = 0 > Messagebox ("Table " + AllTrim (cTable_Name) + IIf (Empty (cTable_Owner), "", " (" + AllTrim (cTable_Owner) + ")") + " has no rows to browse.", (0+64+0), cCaption) > Return > endif > > If nRecCount > 100000 > If Messagebox ("Table " + AllTrim (cTable_Name) + IIf (Empty (cTable_Owner), "", " (" + AllTrim (cTable_Owner) + ")") + " has " + lTrim (Transform (nRecCount, "999,999,999")) + " rows. " + ; > "It may take a while to process, depending on your database server." + Chr (13) + Chr (13) + ; > "Do you want to continue processing ?", (4+32+0), cCaption) = 7 > Return > endif > endif > > gObjtSQLcommand = "Select * From " + IIf (Empty (cTable_Owner), "", cTable_Owner + ".") + cTable_Name > > SQLSetProp (gSQLHandle,"Asynchronous", .F.) > SQLExec (gSQLHandle, gObjtSQLcommand, "CurSQLbrowse") >>In the last lines showed is where I want to put the right sequence of SQL Passthrough commands to loop and be interrupted. In the case above, it will return all records in the table.
SQLDISCONNECT(0) CLOSE DATABASES ALL gSQLHandle = SQLSTRINGCONNECT("Driver=SQL Server;Server=Boris;DataBase=xxxxxxxxx;Trusted_Connection=yes;") gObjtSQLcommand = "Select Count(*) as Records From dbo.Nu" && A table with 2 300 000 records If SqlExec (gSQLHandle, gObjtSQLcommand, "SQLcurCount") <> 1 If Used ("SQLcurCount") Use In SQLcurCount endif Messagebox ("Unexpected SqlExec () error. Browse will not be executed. Sorry.", (0+16+0), cCaption) Return endif Select SQLcurCount If VarType (Records) = "C" && This is because some servers return numeric and others return character nRecCount = Val (Records) else nRecCount = Records ENDIF If nRecCount > 100000 If Messagebox ("Table has " + lTrim (Transform (nRecCount, "999,999,999")) + " rows. " + ; "It may take a while to process, depending on your database server." + Chr (13) + Chr (13) + ; "Do you want to continue processing ?", (4+32+0), "asdasdasd") = 7 Return endif endif gObjtSQLcommand = "Select * From dbo.Nu" SQLSETPROP(gSQLHandle,"Asynchronous" , .t.) CURSORSETPROP("FetchSize" , 300, 0) i = 0 Do While !Used ("CurSQLbrowse") I = I + 1 WAIT WINDOW NOWAIT NOCLEAR "a = "+TRANSFORM(I) SQLExec (gSQLHandle, gObjtSQLcommand, "CurSQLbrowse") ENDDO *ASSERT .f. Do While SQLExec(gSQLHandle, gObjtSQLcommand) = 0 I = I + 1 WAIT WINDOW NOWAIT NOCLEAR I EndDo SQLSetProp (gSQLHandle,"Asynchronous", .F.) CURSORSETPROP("FetchSize" , -1, 0) WAIT WINDOW NOWAIT RECCOUNT()