SQL BROWSER with FIVEWIN + xBrowser

SQL BROWSER with FIVEWIN + xBrowser

Postby MGA » Fri Dec 20, 2019 1:27 pm

:D
Friends, I'm trying to create an internal SQL BROWSER with fivewin. The idea is that when you type QUERY and click RUN, the system loads the browse with the result. But I can't update the browser, could anyone help?

this function does not work:

static procedure PopulaBrowseQuery(cNotes, aResult)
local oData

oData := m->oserver:query( Alltrim(cNotes) )
aResult :=oData:FillArray()

s_oBrowse:setarray(aResult)
s_oBrowse:Refresh()

return


follow the source below:


Image


prg:

#include "fivewin.ch"
#include "xbrowse.ch"
#include "ttitle.ch"

static s_oWndSqlBrowser := Nil, s_oFonteTitle, s_oFonteBold, s_oTitle, s_oBrowse, hLays := {=>}

/******************************************************************************************************/
procedure SQLBrowser()
/*
*/
Local cNotes := 'select * from produtos', oGet, aResult := {}, hButtons := {=>}, oBotao1, oBotao2

if !VerificaWindowsSQLBrowser()
return
endif

DEFINE FONT s_oFonteBold NAME "Times New Roman" SIZE 0,-15
DEFINE FONT s_oFonteTitle NAME "Segoe UI Light" SIZE 0, 32

define window s_oWndSqlBrowser mdichild of M->oWnd title "SQL Browser" color CLR_WHITE,CLR_WHITE

hLays["MAIN"] := TLayout():new( s_oWndSqlBrowser )

hLays["TITLE"] := hLays["MAIN"]:addVLayout(38)
hLays["GET"] := hLays["MAIN"]:addVLayout(120)
hLays["BROWSE"] := hLays["MAIN"]:addVLayout()

//TITLE
@ 0, 0 TITLE s_oTitle size 8, 10 of hLays["TITLE"] SHADOW NOSHADOW
@ 3, 10 TITLETEXT OF s_oTitle TEXT "SQL Browser" FONT s_oFonteTitle
s_oTitle:bGotfocus := {|| xSetFocus(oGet) }
hLays["TITLE"]:oClient := s_oTitle

//get comandos
hLays["GET"]:addHLayout()
hLays["GET"]:addHLayout(80)

@ 0,0 GET oGet VAR cNotes TEXT PIXEL OF hLays["GET"]:aHLayout[1] MEMO font s_oFonteBold multiline
hLays["GET"]:aHLayout[1]:oClient := oGet

oGet:lClrFocus := .t.
oGet:bGotfocus := {|| oGet:setpos(0) }

//botoes
oBotao1 := hLays["GET"]:aHLayout[2]:addVLayout()
oBotao2 := hLays["GET"]:aHLayout[2]:addVLayout()

@ 0,0 btnbmp hButtons["UM"] prompt "F3 Executar" of oBotao1 MULTILINE Action(PopulaBrowseQuery(cNotes, @aResult), xSetFocus(s_oBrowse))
oBotao1:oClient := hButtons["UM"]

@ 0,0 btnbmp hButtons["DOIS"] prompt "&Sair" of oBotao2 MULTILINE Action(s_oWndSqlBrowser:End())
oBotao2:oClient := hButtons["DOIS"]


//browse
@ 0,0 xbrowse s_oBrowse of hLays["BROWSE"] array aResult color CLR_BLACK,RGB(224,236,255)

s_oBrowse:bClrSelFocus := {|| {CLR_WHITE,CLR_HBLUE}}
s_oBrowse:bClrStd := {|| IIf((s_oBrowse:nArrayAt % 2 )==0,{CLR_BLACK, RGB(224,236,255)},{CLR_BLACK,RGB(189, 211,253)})}
s_oBrowse:bClrSel := {|| {CLR_WHITE,RGB(30,144,255)}}
s_oBrowse:nRowHeight := 26
s_oBrowse:nHeaderHeight := 30
s_oBrowse:nMarqueeStyle := 8

s_oBrowse:CreateFromCode()
hLays["BROWSE"]:oClient := s_oBrowse


// s_oWndSqlBrowser:SetIcon( TIcon():New(,,'MGAICON'))

s_oWndSqlBrowser:bPostEnd := {|| MsgRun("Aguarde...",,{|| Valid_SQLBrowser() } ) }

activate window s_oWndSqlBrowser maximized on init(xSetFocus(oGet));
valid( s_oWndSqlBrowser := Nil, .t. )

return

/************************************************************************************/
static procedure PopulaBrowseQuery(cNotes, aResult)
/*
*/
local oData

oData := m->oserver:query( Alltrim(cNotes) )
aResult :=oData:FillArray()

s_oBrowse:setarray(aResult)
s_oBrowse:Refresh()

return

/************************************************************************************/
static procedure Valid_SQLBrowser()
/*
*/
s_oFonteBold:end()
s_oFonteTitle:end()
s_oTitle:end()
HB_GCAll(.t.)
return

/************************************************************************************/
static function VerificaWindowsSQLBrowser()
/*
*/
if s_oWndSqlBrowser != Nil
if !IsZoomed(s_oWndSqlBrowser:hWnd)
s_oWndSqlBrowser:Maximize()
endif
return(.f.)
endif
return(.t.)
ubiratanmga@gmail.com

FWH18.02
FWPPC
Harbour/xHarbour
xMate
Pelles´C
TDolphin
MGA
 
Posts: 1234
Joined: Mon Feb 25, 2008 2:54 pm
Location: Brasil/PR/Maringá

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby Jimmy » Sat Dec 21, 2019 4:32 am

hi,

as Port is 3306 i guess we talk about MySQL

the Code which you take from Sample c:\fwh\samples\testage4.prg is using c:\fwh\lib\dolphin.lib

---

try :

c:\fwh\samples\mysql1.prg
c:\fwh\samples\erp.prg
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1587
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby nageswaragunupudi » Sat Dec 21, 2019 7:41 am

Image

Fully functional program with FWH1909, using FWH built-in MySql library:
Code: Select all  Expand view
#include "fivewin.ch"

function Main( cParam )

   local oDlg, oFont, oFixed, oGet, oBrw
   local oCn, oRs, cSql

   TMultiGet():lClrFocus   := .t.
   SET DATE ITALIAN
   SET CENTURY ON

   FW_SetUnicode( .t. )

   if Empty( cParam )
      oCn   := FW_DemoDB()
   else
      oCn   := maria_Connect( cParam )
   endif

   if oCn == nil
      return nil
   endif

   cSql  := "SELECT Now()"
   oRs   := oCn:RowSet( cSql, .T. )

   DEFINE FONT oFont  NAME "TAHOMA"         SIZE 0,-14
   DEFINE FONT oFixed NAME "LUCIDA CONSOLE" SIZE 0,-18

   DEFINE DIALOG oDlg SIZE 900,700 PIXEL TRUEPIXEL FONT oFont ;
      TITLE FWVERSION + " : MySQL QUERY BROWSER"

   @  20,20 GET oGet VAR cSql MEMO SIZE 840,150 PIXEL OF oDlg UPDATE FONT oFixed

   oGet:bValid := <|o|
      if Upper( cSql ) == Upper( oRs:Source )
         return .t.
      endif
      CursorWait()
      if oRs:Requery( cSql )
         oRs:SetXbrColumns( oBrw )
         oBrw:GoTop()
         oBrw:Refresh()
         return .t.
      endif
      MsgAlert( "Invalid SQL" )
      return .f.
      >

   @ 190,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg DATASOURCE oRs ;
      AUTOCOLS CELL LINES NOBORDER FOOTERS

   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTERED ON INIT oGet:SetFocus()
   RELEASE FONT oFont, oFixed

return nil
 


By default, the program connects to the MySQL server freely provided by FWH.
By specifying the parameters, we can also connect to our own server.
eg:
mysqlqry server,db,user,password
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby Jimmy » Sat Dec 21, 2019 9:20 am

nageswaragunupudi wrote:Fully functional program with FWH1909, using FWH built-in MySql library:

By default, the program connects to the MySQL server freely provided by FWH.
By specifying the parameters, we can also connect to our own server.
eg:
mysqlqry server,db,user,password

WOW ... :D

is something like this available for PostgreSQL :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1587
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby MGA » Sat Dec 21, 2019 1:05 pm

Mr Nages,

is possible com TDOLPHIN?

oRs:SetXbrColumns( oBrw ) ?

Thanks
ubiratanmga@gmail.com

FWH18.02
FWPPC
Harbour/xHarbour
xMate
Pelles´C
TDolphin
MGA
 
Posts: 1234
Joined: Mon Feb 25, 2008 2:54 pm
Location: Brasil/PR/Maringá

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby MGA » Thu Jan 02, 2020 12:09 pm

Mr Nages,

is posslble?
ubiratanmga@gmail.com

FWH18.02
FWPPC
Harbour/xHarbour
xMate
Pelles´C
TDolphin
MGA
 
Posts: 1234
Joined: Mon Feb 25, 2008 2:54 pm
Location: Brasil/PR/Maringá

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby nageswaragunupudi » Thu Feb 11, 2021 6:21 pm

MGA wrote:Mr Nages,

is posslble?


Please open new query and if successfully opened, try
oBrw:SetDolphin( oNewQry, .t. )

Mr. Jimmy
For PostGre SQL also please try the same thing
oBrw:SetPostGre( oNewQry, .t. )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby MGA » Thu Feb 11, 2021 9:07 pm

Sr. Nages,

New columns are always added, with each new query, new columns are added. I'm not able to clear the previous query to get only the columns for the new query.


s_oResult := M->oServer:Query( cNotes )
s_oData := s_oResult
s_oBrowse:SetDolphin(s_oData, .t.)
s_oBrowse:GoTop()
s_oBrowse:Refresh()
ubiratanmga@gmail.com

FWH18.02
FWPPC
Harbour/xHarbour
xMate
Pelles´C
TDolphin
MGA
 
Posts: 1234
Joined: Mon Feb 25, 2008 2:54 pm
Location: Brasil/PR/Maringá

Re: SQL BROWSER with FIVEWIN + xBrowser

Postby MGA » Thu Feb 11, 2021 9:20 pm

Mr Nages solved the problem. Thanks

s_oData := M->oServer:Query( cNotes )
s_oData:refresh()
s_oBrowse:acols := {}
s_oBrowse:SetDolphin(s_oData, .t.)
s_oBrowse:GoTop()
s_oBrowse:Refresh()
ubiratanmga@gmail.com

FWH18.02
FWPPC
Harbour/xHarbour
xMate
Pelles´C
TDolphin
MGA
 
Posts: 1234
Joined: Mon Feb 25, 2008 2:54 pm
Location: Brasil/PR/Maringá


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 104 guests