SET TALK off
SET STATUS BAR OFF
SET SYSMENU off
SET DELETED on
SET CONFIRM OFF
SET NOTIFY off
SET SAFETY off
SET CENTURY ON
SET DATE TO DMY
SET FIXED OFF
SET DECIMALS TO 5
SET ESCAPE On

_screen.WindowState = 1


SET PATH TO proj,json,classes, form,prg,class, source

_screen.Caption = 'gs - Server '
_screen.AutoCenter= .T.
_screen.Icon = 'glib.ICO'
_screen.Width  = 700
_screen.height = 500

_screen.Closable = .f.
_screen.AutoCenter = .t.
_screen.Show
_screen.BorderStyle=3
_screen.MaxButton= .F.
_screen.ControlBox= .F.
_screen.ControlBox= .T.
_screen.MaxButton= .T.
_screen.Closable = .T.
_screen.WindowState = 2


ON ERROR DO errhand 
PUBLIC o
o = CREATEOBJECT ('ClassDb')

DO FORM gs_seccion

READ events

o.closeDB()

ON ERROR

DEFINE CLASS ClassDb AS CUSTOM 

cPathBin = ''
nConn = -1
cSeccion = 'g1191724778001'

cPuertoext   = ""
cDBPassword	 = ""

cHost = "localhost"

PROCEDURE init ()
	
	this.nConn = SQLCONNECT('fss1')
	
	this.sqlexec("show variables where variable_name = 'basedir'",'curBin')
	this.cPathBin = ALLTRIM(STRTRAN(curBin.value,CHR(0),''))+'/bin/'
	
*!*		this.cPuertoext      = ALLTRIM(this.setup('cPuertoext','C'))
*!*		this.cDBPassword	 = ALLTRIM(this.setup('cDBPassword','C'))
*!*		this.cPuertoext      = IIF(!EMPTY(this.cPuertoext),' --port=','')+this.cPuertoext
*!*		this.cDBPassword	 = IIF(!EMPTY(this.cDBPassword),' --password=','')+this.cDBPassword
	
	IF !DIRECTORY('temp')
		MKDIR temp
	ENDIF
		
ENDPROC


FUNCTION Config
PARAMETERS _llave
	
	nRet = .F.
	IF this.sqlexec('CALL config(?_llave)')>0
		nRet = sqlresult.valor
	ENDIF
	
	RETURN nRet
ENDFUNC

FUNCTION SetConfig
PARAMETERS _llave,_valor
	
	this.sqlexec('CALL setconfig(?_llave,?_valor)')

ENDFUNC

FUNCTION newConfig
PARAMETERS _llave,_valor
	
	this.sqlexec('CALL newconfig(?_llave,?_valor)')

ENDFUNC

FUNCTION sqlexec(cCad,cCursor)

	IF SQLEXEC(this.nConn,cCad,IIF(EMPTY(cCursor),'sqlresult',cCursor),aInfo)<0
		DO errhand
	ENDIF
	

	RETURN aInfo[2]
ENDFUNC


FUNCTION closeDB
	IF This.nConn>0
		SQLDISCONNECT(This.nConn)
	ENDIF
ENDFUNC

PROCEDURE setSeccion (cSeccion)
	IF !EMPTY(cSeccion)
		this.cSeccion = 'g'+cSeccion
	ENDIF
ENDPROC


FUNCTION execMySqlScript(cSql)

	WAIT WINDOW NOWAIT 'Instalando procedimientos almacenados...'

	STRTOFILE(cSql,'temp\pa.sql')
	cmd = this.cPathBin+'mysql.exe < temp\pa.sql -u root ' + this.cPuertoExt + this.cDBPassword
	RUN &cmd

ENDFUNC
ENDDEFINE


PROCEDURE errhand
	=AERROR(aErrorArray)  
  	
  	cErr = ''
  	FOR __n__= 1 TO 7
  		IF !ISNULL(aErrorArray(__n__))
	      	cErr = cErr +  TRANSFORM(aErrorArray(__n__))+CHR(13)
	    ENDIF
   	ENDFOR
	   	
   MESSAGEBOX(cErr+CHR(13)+MESSAGE(1),63,'Ghost-Errores')
   CLEAR EVENTS
   cancel
ENDPROC