HRB V/S LIB

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
serge_girard
Posts: 1873
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 295 times
Been thanked: 67 times
Contact:

Re: HRB V/S LIB

Post by serge_girard » Thu Apr 13, 2017 3:19 pm

Hello Luis, That won't change much? Now you will have to install new HRB instead of EXE?

Serge

User avatar
Anand
Posts: 210
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 24 times
Been thanked: 33 times

Post by Anand » Thu Apr 13, 2017 4:23 pm

+1, and a very small one. Most probably just copy to exe folder.

Regards,

Anand
Image

User avatar
serge_girard
Posts: 1873
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 295 times
Been thanked: 67 times
Contact:

Post by serge_girard » Fri Apr 14, 2017 7:16 am

Anand, I use a BAT file to start up my programs. In this batch file 2 programs are executed. The first program just looks in a MySQL table if a new version of the main program is avaiable. If so the old main program is renamed and a new copy is downloaded. Then the second program is started which by then maybe the latest version. Of course MySQL / libmysql.dll is required but this works perfect. From my place I upload the EXE and choose to whom it may serve.

Serge

User avatar
Anand
Posts: 210
Joined: Tue May 24, 2016 4:36 pm
DBs Used: DBF
Has thanked: 24 times
Been thanked: 33 times

Post by Anand » Fri Apr 14, 2017 9:32 am

Good idea. Thanks

Regards,

Anand
Image

User avatar
mol
Posts: 2856
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 126 times
Been thanked: 65 times
Contact:

Post by mol » Thu May 18, 2017 6:05 am

Hi!
I want to refresh this topic.
What about speed of functions placed in .hrb files? Is it comparable to functions located in .exe?

User avatar
dragancesu
Posts: 462
Joined: Mon Jun 24, 2013 11:53 am
DBs Used: DBF, MySQL, Oracle
Location: Subotica, Serbia
Has thanked: 3 times
Been thanked: 67 times

Post by dragancesu » Thu May 18, 2017 6:18 am

I use a BAT file to start up my programs. In this batch file 2 programs are executed. The first program just looks in a MySQL table if a new version of the main program is avaiable. If so the old main program is renamed and a new copy is downloaded. Then the second program is started which by then maybe the latest version. Of course MySQL / libmysql.dll is required but this works perfect. From my place I upload the EXE and choose to whom it may serve.
if I understand you solved the problem of synchronization / update of new versions

Can you put some code how are you doing?

Whether it can work in the startup section of the windows?

thanks

User avatar
serge_girard
Posts: 1873
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 295 times
Been thanked: 67 times
Contact:

Post by serge_girard » Thu May 18, 2017 7:53 am

Hi Dragan,

I use in my BAT file 2 EXE:

The first is a short program which runs locally on several PC at different locations. Each time a new version is
ready to be implemented I transfer the EXE to a MySQL database.

Structure is simple: FILE C(30), POS N(10), STATUS (C1), EXE_FILE (Longblob)

STATUS == 'N' indicates that a new version is ready to be downloaded for a specific POS (or all).

So the first program checkes if there is a new version.
If there is:
- I rename the existant EXE to the same name with date + sequential number in order to have a backup of the previous version.
- I retrieve the EXE into a var and from this var I create a EXE file (Buff_To_File).

Then the program is ready and quits and the batch will continue with the new version.
The second program (the main program which is all about) will do the same for the first program (this seldom happens, of course)

So there are 3 programs involved:
2 remote
1 HQ.

From the HQ program I can copy a new EXE to this MySQL database and reset the STATUS to 'N' and the I can check if all went OK.

You will need libmysql.dll on each PC and a remote MySQL database for your tables.


I include a short extract (not compile tested) which does the thing.

Code: Select all

#include "hmg.ch"


FUNCTION MAIN()
/*************/
PARAMETERS xPOS

// CHECK xPOS !!

// GET  xDB_HOST,xDB_USER,xDB_PW,xDB_NAME


IF SQL_Connect(xDB_HOST,xDB_USER,xDB_PW,xDB_NAME)  == Nil 
   // CONTINUE
	QUIT
ENDIF

NEW_VERSION()
 
SQL_Disconnect()

RETURN





FUNCTION NEW_VERSION()
/******************/
cQuery1	:= " SELECT EXE_FILE "  
cQuery1	+= " FROM NEW_VERSION "  
cQuery1	+= " WHERE FILE		= 'ZZZ' "			 
cQuery1	+= " AND   STATUS		= 'N' "				 
cQuery1	+= " AND   POS 		= '" + xPOS + "' "				 
cSQL		:= cQuery1
cQuery1	:= dbo:Query( cQuery1 )
IF cQuery1:NetErr()												
   ? PROCNAME(), '010', cQuery1:Error() , cSQL  
   RETURN 
ENDIF 


NIEUW := FALSE

IF cQuery1:LastRec() == 0
	RETURN
ELSE
   aCurRow		:= cQuery1:GetRow(1)
   cEXE  	   := aCurRow:fieldGet(1)
   IF EMPTY(cEXE)
      RETURN
   ELSE
      // COPY TO ..
      dDATUM = DTOC(DATE())
      dDATUM = STRTRAN(dDATUM,"/","") 
      dDATUM = STRTRAN(dDATUM,"-","") 
      nVOLG  = 1
	
      DO WHILE .T.  
         cOLDFILE = "&XSTAT_PATH\ZZZ" + dDATUM + ALLTRIM(STR(nVOLG,3,0)) + ".EXE"
         IF !FILE(cOLDFILE)
            EXIT
         ENDIF
         nVOLG++
      ENDDO

      IF FRENAME("&XSTAT_PATH\ZZZ.EXE", cOLDFILE)  == -1
         QUIT
      ENDIF

      NIEUW := Buff_To_File(cEXE, "&XSTAT_PATH\ZZZ.EXE")

      IF !NIEUW
         ? 'Kopieeren nieuwe ZZZ is fout' , 'OK'
         // RESTORE PREV VERSION 
         IF FRENAME(cOLDFILE, "&XSTAT_PATH\ZZZ.EXE" )  == -1
            QUIT
         ENDIF
         RETURN
      ENDIF
   ENDIF
ENDIF


IF NIEUW
 	IF FRENAME("&XSTAT_PATH\ZZZ.EXE", cOLDFILE)  == -1
		QUIT
	ENDIF
 
	cQuery1	:= " UPDATE NEW_VERSION "	   
	cQuery1	:= " SET   STATUS    = 'X' " 
   cQuery1	+= " WHERE FILE		= 'ZZZ' "			 
   cQuery1	+= " AND   STATUS		= 'N' "				 
   cQuery1	+= " AND   POS 		= '" + xPOS + "' "				 
	cSQL		:= cQuery1
	cQuery1	:= dbo:Query( cQuery1 )

	IF cQuery1:NetErr()					// hier fout							
		?  PROCNAME(), '013', cQuery1:Error() , cSQL 
		RETURN
	ENDIF
 
ENDIF


RETURN


FUNCTION Buff_To_File(cBuff, cNEW_FILE)
/*************************************/
LOCAL fh, nLen

fh := FCREATE(cNEW_FILE,0)

IF fh > - 1
	nLen	:= FWRITE(fh, cBuff) 
	FCLOSE(fh)

	IF nLen == LEN(cBuff)
      RETURN .T.	 
	ELSE
		RETURN .F.
	ENDIF
ENDIF

RETURN .F.	 
No magic, no tricks...

For inserting EXE I use this code:

Code: Select all

cEXE_File   := File_To_Buff( LclFile0 )
cQuery1	:= " INSERT INTO NEW_VERSION "  
etc...



FUNCTION File_To_Buff(cFile)
/*******************************************************************************************************************/
local cBuff:="", fh, nLen
local lRetVal:=.f.
local cFile_in := cFile


fh	:= FOPEN(cFile_in,0)

IF fh > -1
   // determine length of file
   nLen := FSEEK(fh, 0, 2)

   IF nLen > 0
		//move file pointer back to begin of file
		FSEEK(fh, 0, 0)
		cBuff	:= SPACE(nLen)
		FREAD(fh, @cBuff, nLen)
		 
		// escapes
		cBuff	:= STRTRAN(cBuff, CHR(92), "\\")
		cBuff	:= STRTRAN(cBuff, CHR(0), "\0")
		cBuff	:= STRTRAN(cBuff, CHR(39), "\'")
		cBuff	:= STRTRAN(cBuff, CHR(34), '\"')
	ENDIF 
ELSE
   cBuff := "OFF"       
ENDIF
     
FCLOSE(fh)

RETURN(cBuff)
Serge

User avatar
luisvasquezcl
Posts: 1034
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Has thanked: 11 times
Been thanked: 14 times
Contact:

Post by luisvasquezcl » Fri May 19, 2017 12:43 am

Wow im impresive. Thanks serge. Best regards
Luis vasquez

franco
Posts: 203
Joined: Sat Nov 02, 2013 5:42 am
DBs Used: DBF
Been thanked: 6 times

Post by franco » Fri May 19, 2017 3:56 am

Like I said before, so much to learn, so little time.
Serge with this is a great sample, to me seems you are saving the exe file in a table. Then extracting it at the other end. Is this so.
I know before you mentioned you upload each night from pos to HQ. Does each pos have its own folder in the server to upload the tables to.
I am still trying to figure out sql of some type, but having trouble understanding. I will get it I know.
Nice work ... Franco

User avatar
serge_girard
Posts: 1873
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 295 times
Been thanked: 67 times
Contact:

Post by serge_girard » Fri May 19, 2017 7:46 am

No folder/dir for each POS. Each POS has it's unique POS_NO.
EXE is indeed saved in MySQL table. About 5-6Mb and it is downloaded really quickly. Most users will not notice, except after downloading I give a message saying that a new version has been installed.

Serge

Post Reply