how postgreSQL connect

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: how postgreSQL connect

Post by jairpinho »

AUGE_OHR wrote: Sat Aug 31, 2019 8:59 pm hi,

thx again for your help an demo code.

i saw that

Code: Select all

        WIDTHS { 100,300,100,150,400}
        HEADERS { 'Code' , 'Name' , 'Salary' , 'Creation' , 'Description' }
are in *.FMG

there are a lot of PRIVATE in your new code and it is still fix on given Table.
i want to use GRID for any Table so i have to modify your code as i did in my 1st Sample.

to get WIDTHS and Header i use this code with Xbase++

Code: Select all

METHOD PGSql:dbStruct( cTable )
LOCAL aStruct    := {}
LOCAL oStruct, i, iMax
LOCAL cField, cType, nLen, nDec
LOCAL cWhere     := ""
LOCAL cData_type := ""

   ::exec( "SELECT column_name, data_type, character_maximum_length, numeric_precision, numeric_scale " + ;
           "FROM information_schema.columns WHERE table_name='" + cTable + "'" + ;
           "ORDER BY ordinal_position" )

   oStruct := ::result
   iMax := oStruct:rows                                   
   FOR i = 1 TO iMax                                       

      cField := oStruct:GetValue( i - 1, 0 )
      cData_type := UPPER( ALLTRIM( oStruct:GetValue( i - 1, 1 ) ) )

      DO CASE
         CASE cData_type = "BOOLEAN"
            cType := "L"
            nLen := 1
            nDec := 0

         CASE cData_type = "CHARACTER"
            cType := "C"
            nLen := oStruct:FieldGet( i - 1, 2 )
            nDec := 0

         CASE cData_type = "DATE"
            cType := "D"
            nLen := 10
            nDec := 0

         CASE cData_type = "TEXT"
*           cType := "M"
            cType := "C"
            nLen := oStruct:FieldGet( i - 1, 2 )
            nDec := 0

         CASE cData_type = "NUMERIC"
            cType := "N"
            nLen := oStruct:FieldGet( i - 1, 3 )
            nDec := oStruct:FieldGet( i - 1, 4 )

         CASE cData_type = "INTEGER"
            cType := "N"
            nLen := oStruct:FieldGet( i - 1, 3 )
            nDec := oStruct:FieldGet( i - 1, 4 )

         CASE cData_type = "SERIAL"
            cType := "N"
            nLen := oStruct:FieldGet( i - 1, 3 )
            nDec := oStruct:FieldGet( i - 1, 4 )

            // byteA -> HEX -> Bitmap
            //
         CASE cData_type = "BYTEA"
            cType := "B"
            nLen := 10
            nDec := 0

            // large Object
            //
         CASE cData_type = "OID"
            cType := "O"
            nLen := 10
            nDec := 0

         OTHERWISE
            MSGBOX( "unknown type " + cData_type )
            cType := "C"
            nLen := 1
            nDec := 0
      ENDCASE

      AADD( aStruct, { cField, cType, nLen, nDec } )
   NEXT

RETURN ( aStruct )
are in *.FMG ? that's right on main.fmg


there are a lot of PRIVATE in your new code and it is still fix on given Table.
i want to use GRID for any Table so i have to modify your code as i did in my 1st Sample.

there are a lot of PRIVATE in your new code and it is still fixed on given Table? variables for form I use private
i want to use GRID for any table so i have to modify your code as i did in my 1st Sample? you have to do manual or use a function to return the amount of fields you can use any already used if it works, so I put the example of using a vector in main.fmg form due to the ease of manipulating this data being manual or automated.
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: how postgreSQL connect

Post by AUGE_OHR »

hi,

sorry about my Question.
i begin with harbour / HMG while my Source is Xbase++ Syntax so i'm still a Newbie.

is that code in Main.Fmg generate by HMG IDE :?:

---

i found in include postgreSQL.Prg

Code: Select all

FUNCTION pgSelectQuery() 
how aTable is prepare.
later each Element for GRID will add using "ADDITEM" ...

GRID seems to have LVN_GETDISPINFO / LVS_OWNERDATA :?:
as i have Array aTable i like to use LVN_GETDISPINFO / LVS_OWNERDATA so i must not "addItem" ...

---

PostgreSQL LibPG / CLASS TPQServer

i begin to understand how CLASS TPQServer work. where can i get hole source ?
as i have Xbase++ CLASS like TPQServer it try to compile it but some PG* Function are unknown :!:

Code: Select all

PQfreemem()
PQCONNECTPOLL()
PQRESETSTART()
PQRESETPOL()
PQFINISH()
PQESCAPESTRINGCONN()
PQBACKENDPID()
PQSOCKET()

PQRESSTATUS()
PQCLEAR()
p.s. these PG* Function are from v7.3
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: how postgreSQL connect

Post by AUGE_OHR »

have found tpostgre.prg which have 3 CLASS

Code: Select all

TPQServer
TPQQuery
TPQRow
this is to "communicate" via LibPQ.DLL and Pg-Server

CLASS TPQquery include all what i need for "DbSkipper"

Code: Select all

   // Navigation code blocks for the browser
   ::skipBlock     := {|n| (::DbSkipper(n)) }
   ::goTopBlock    := {| | (::oPG:GoTop())      }
   ::goBottomBlock := {| | (::oPG:GoBottom())   }

   ::phyPosBlock   := {| | (::oPG:recNo())        }

   // Navigation code blocks for the vertical scroll bar
   ::posBlock      := {| | (::oPG:Position())    }
   ::goPosBlock    := {|n| (::oPG:GoPosition(n)) }
   ::lastPosBlock  := {| | 100             }
   ::firstPosBlock := {| | 0               }
   ...
   

   
method CLASS_NAME:dbSkipper( n )
   local nDir
   local nDone := 0

   default n to 0
   nDir := iif( n > 0, 1, -1 )

   while n <> 0 .and. iif( nDir > 0, !::oPG:eof(), !::oPG:bof() )
      ::oPG:Skip(nDir)
      if ::oPG:eof()
         exit
      elseif ::oPG:bof()
         exit
      endif
      if !Eval(::whileClause)
         ::oPG:Skip(-nDir)
         if !Eval(::whileClause) // oops, no recs available
            ::oPG:GoBottom()
            ::oPG:Skip()
         endif
         exit
      endif
      n     -= nDir
      nDone += nDir
   enddo
   
   if valtype(::cChild) == "O"
      ::cChild:goTop()
      ::cChild:refreshAll()
   endif
   return (nDone)
this Way i can direct browse in Result-Set of Query
(have to make a Datalink and build Column as usual)

---

32 Bit connection work but i'm still stuck with 64 Bit :cry:
i have only 32 Bit libhbpgsql.a and not libhbpgsql-64.a for Ming64 so i get PQ* Error
have fun
Jimmy
User avatar
jairpinho
Posts: 420
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Contact:

Re: how postgreSQL connect

Post by jairpinho »

AUGE_OHR wrote: Wed Sep 04, 2019 2:18 am have found tpostgre.prg which have 3 CLASS

Code: Select all

TPQServer
TPQQuery
TPQRow
this is to "communicate" via LibPQ.DLL and Pg-Server

CLASS TPQquery include all what i need for "DbSkipper"

Code: Select all

   // Navigation code blocks for the browser
   ::skipBlock     := {|n| (::DbSkipper(n)) }
   ::goTopBlock    := {| | (::oPG:GoTop())      }
   ::goBottomBlock := {| | (::oPG:GoBottom())   }

   ::phyPosBlock   := {| | (::oPG:recNo())        }

   // Navigation code blocks for the vertical scroll bar
   ::posBlock      := {| | (::oPG:Position())    }
   ::goPosBlock    := {|n| (::oPG:GoPosition(n)) }
   ::lastPosBlock  := {| | 100             }
   ::firstPosBlock := {| | 0               }
   ...
   

   
method CLASS_NAME:dbSkipper( n )
   local nDir
   local nDone := 0

   default n to 0
   nDir := iif( n > 0, 1, -1 )

   while n <> 0 .and. iif( nDir > 0, !::oPG:eof(), !::oPG:bof() )
      ::oPG:Skip(nDir)
      if ::oPG:eof()
         exit
      elseif ::oPG:bof()
         exit
      endif
      if !Eval(::whileClause)
         ::oPG:Skip(-nDir)
         if !Eval(::whileClause) // oops, no recs available
            ::oPG:GoBottom()
            ::oPG:Skip()
         endif
         exit
      endif
      n     -= nDir
      nDone += nDir
   enddo
   
   if valtype(::cChild) == "O"
      ::cChild:goTop()
      ::cChild:refreshAll()
   endif
   return (nDone)
this Way i can direct browse in Result-Set of Query
(have to make a Datalink and build Column as usual)

---

32 Bit connection work but i'm still stuck with 64 Bit :cry:
i have only 32 Bit libhbpgsql.a and not libhbpgsql-64.a for Ming64 so i get PQ* Error
hello please send the complete 32 bit project example that is working i will test, follow lib 64
Attachments
libpgsql-64.zip
(7.3 KiB) Downloaded 207 times
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: how postgreSQL connect

Post by AUGE_OHR »

hi,
jairpinho wrote: Wed Sep 04, 2019 2:33 am hello please send the complete 32 bit project example that is working i will test, follow lib 64
Thx for Upload but these files are only "SQL Bridges for MySQL,PostgreSQL and SQLite"

---

32 Bit libhbpgsql.a is a "Import" LIB from PostgreSQL LibPG.LIB.
it contain Import PQ* Function to use with LibPG.DLL

for 64 Bit we need a libhbpgsql-64.a but it seems nobody have build it yet :?:
have fun
Jimmy
Post Reply