Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem with SQLExec () sequences
Message
 
To
15/11/2012 16:37:08
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01557240
Message ID:
01557401
Views:
73
This message has been marked as the solution to the initial question of the thread.
>>I'll check it tomorrow against SQL Server.
>
>Thanks Borislav.
>
>In the "List of Available Tables" in the "ODBC Connection" menu, if you select the "Browse" button, it will execute the following code, note that THIS is the code I want to change:
>
>                      
> 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.
>
>Other option, where you have the control of your SQL command is to select the button "Exec SQL" in the "List of Available Tables". You will be presented with a screen where you can write your SQL commands the way you like (the syntax is of the database server you're using) and execute them.


That works for me (SQL Server):
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()
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform