Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using SQLEXEC() for a TSQL file...
Message
From
02/09/2002 07:14:37
 
 
To
02/09/2002 03:17:18
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00695487
Message ID:
00695902
Views:
14
Hello,

here some snippet of source-code from the Article 'Managing SQL Server/MSDE from VFP - Part III' (published in FoxTalk Magazine October 2001)

i've slightly modified it to conform with the code in the previous post

* Use SPT to run the batch
* Because SPT can't run multiple batches separated
* with GO, breack up the statements using string
* manipulation
ln_conn = SQLCONNECT("DataSource")
lc_file = FILETOSTR("sql.txt")

lnBatches = OCCURS('GO' + CR ,UPPER(lc_file) )+ 1
    
  FOR lnBatch = 1 TO lnBatches
  
    * find the text between the current GOs
    lnFirstGo = IIF(lnBatch = 1, 1 - LEN('GO' + CR), ;
      AT('GO' + CR, UPPER(lc_file);
      , lnBatch - 1))
    lnLastGo = IIF(lnBatch = lnBatches, ;
      LEN(lc_file) + 1, AT('GO' + ;
      CR, UPPER(lc_file), lnBatch))
    lcSQL = SUBSTR(lc_file, ;
      lnFirstGo + LEN('GO' + CR), lnLastGo - ;
      lnFirstGo - LEN('GO' + CR))

    * run this batch
    lnResult = SQLExec(ln_conn, lcSQL)
    IF lnResult <> 1
      LOCAL laError[1]
      AERROR(laError)
      ** Display Error
      EXIT
    ENDIF

  ENDFOR
Regards

Christian
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform