Function createthread on vfp2c32 library

Topics: Attention VFPX Admins, General
Jun 15, 2011 at 7:53 AM

Dear all,

I´m new in this forum. I'm tried to work with vfp2c32 library and I have one question for createthread function. I have an application on vfp9 and a bbdd on mysql. My application use some tables from mysql server and also one temporary table. I have to upload a text file into the temporary table, but i don´t know if i can do it with multithreating. Is it possible?

 

m.lcConnStr = [DRIVER={MySQL ODBC 5.1 Driver};]

[SERVER=10.102.192.12 ;][DATABASE=nbd;] [UID=user;] 
[PASSWORD=pass;] ("fich10.txt"), [\], [/]) m.lcSQL =[LOAD DATA LOCAL INFILE ']

this.oSaveThread =

NULL
 

 

this.oSaveThread = CreateThreadObject( [savedata.ABigData] , thisform

, .T.)

this.oSaveThread.DoSave(m.lcConnStr, m.lcSQL)

I have to do this (with multitheating) because sometimes the text file is very big and the application show the message (not responding). While i want to show a progressbar, por example.

Could you help me please?

Best regards

m.lcFile =STRTRAN(FULLPATH 

lcFile + ;

[' INTO TABLE vzap FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n' IGNORE 2 LINES]

Developer
Jun 16, 2011 at 6:30 PM

Hi,

you can do it with multithreading, the other option you have is using asyncronous SQL calls.

e.g.

lnCon = SQLCONNECT('yourdsn', ...)
SQLSETPROP(lnCon, 'Asynchronous', .T.)
SQLEXEC(lnCon, ...) && your INSERT statement 

then periodically check if the statement has finished

IF SQLEXEC(lnCon) = 1 && statement has finished
ELSE
ENDIF

In both cases you won't be able to show the "real" progress since Mysql will not return anything while it executes the statement.

I would try this approach first, going for multithreading is probably overkill in this situation.

Christian

Jun 17, 2011 at 7:30 AM

Hi Chistian,

The asyncronous call i think is not valid for me, because the statement Sqlexec load a txt file about 2 million recors, and the process stop on this statement and I can´t do anything.

If I won´t be able to show the 'real' progress, I could put in the main program a object with .avi to say ' load data '... for example. But with asynchronous mode, the avi stop when the file is loading.

Could you help me?

Regards

Developer
Jun 17, 2011 at 6:25 PM
Edited Jun 17, 2011 at 8:53 PM

Hi,

SQLEXEC in Asynchronous mode should not block the execution of your program!
But anyway:

Create a new project with a "main.prg" or a name of your liking:

 

DEFINE CLASS AsyncronousSQL AS Session OLEPUBLIC

   FUNCTION SendSQL(lcConnStr AS String, lcSql AS String) AS VOID

      LOCAL lnCon
      m.lnCon = SQLSTRINGCONNECT(m.lcConnStr)
      IF m.lnCon = -1
        && use AERROR to retrieve error info and pass that back with COMRETURNERROR
      ENDIF

      IF SQLEXEC(m.lnCon, m.lcSql) = -1
         SQLDISCONNECT(m.lnCon)
        && use AERROR to retrieve error info and pass that back with COMRETURNERROR
      ENDIF

      SQLDISCONNECT(m.lnCon)
   ENDFUNC

ENDDEFINE

 

compile this project into a COM-multihreaded dll.

In your main project you can use following assuming you're using the code in some form.

Create the "OnCallComplete" and "OnError" methods on your form (have a look at the VFP2C32 help file for actual parameters ...),

then somewhere create the above COM class and use it.

&& create your pseudo progressbar ...
THISFORM.oThread = CREATETHREADOBJECT('NameOfProjectAbove.AsyncronousSQL', THISFORM)
THISFORM.oThread.SendSQL('the connectionstring', 'your insert SQL')

 


 

In the "OnCallComplete" method put code to close the progressbar, in "OnError" put code to close the progressbar and show/log the Error.

Jun 21, 2011 at 7:33 AM

Hi all,

I have done like you told me. I have created a multithread dll. I have created all methods. But in the statement where I call to CREATHEREADOBJECT the system return the following error

' Resource file version mismatch '

Could you help me? How can I resolve this error?

Regards

Jun 21, 2011 at 7:35 AM

Sorry! FYI I'm using VFP9

Developer
Jun 21, 2011 at 6:27 PM
Edited Jun 21, 2011 at 6:28 PM

Hi,

sounds like an issue with your environment.

This thread should help you http://www.tek-tips.com/viewthread.cfm?qid=1329340&page=1