Page 2 of 4

Re: PostgreSql Libs not ready yet ?

Posted: Thu Jul 16, 2020 11:31 pm
by salamandra
Hi Jimmy,
Finally I got to install PostgreSql v8.3 succesfully.
With this version, I got connect an create a table named 'Test", and also insert and load all records in the table in a browse (not Grid) control.

PgSql_ok.JPG
PgSql_ok.JPG (103.04 KiB) Viewed 2949 times

But, nothing it´s perfect. Take a look to the Browse control....YES, it don´t has Vertical scrollbar.
When you set VScrollBar to .T. it happens this runtime error...

PgSql_error.JPG
PgSql_error.JPG (56.67 KiB) Viewed 2949 times

This error it´s related to this function in h_browse.prg:

Code: Select all

Procedure _BrowseVscrollUpdate (i)
*------------------------------------------------------------------------------*
Local ActualRecord , RecordCount , KeyCount 

	// If vertical scrollbar is used it must be updated
	If _HMG_SYSDATA [  5 ] [i] != 0

		KeyCount := OrdKeyCount()
		If KeyCount > 0
			ActualRecord := OrdKeyNo()
			RecordCount := KeyCount
		Else
			ActualRecord := RecNo()
			RecordCount := RecCount()
		EndIf

		_HMG_SYSDATA [ 37 ] [i] := RecordCount

		If RecordCount < 100
			SetScrollRange (_HMG_SYSDATA [  5 ] [i] , 2 , 1 , RecordCount , .t. )
			SetScrollPos ( _HMG_SYSDATA [  5 ] [i] , 2 , ActualRecord , .T. )
		Else
			SetScrollRange (_HMG_SYSDATA [  5 ] [i] , 2 , 1 , 100 , .t. )
			SetScrollPos ( _HMG_SYSDATA [  5 ] [i] , 2 , Int ( ActualRecord * 100 / RecordCount ) , .T. )
		EndIf

	EndIf

Return
I did not get to load the table succesfully in a Grid control, there was too many runtime errors. I´ll try again with a Grid Control.
Did you get ?


Best regards,


Salamandra, Brazil

Re: PostgreSql Libs not ready yet ?

Posted: Fri Jul 17, 2020 12:10 am
by salamandra
Hi JairPinho,
jairpinho wrote: Thu Jul 16, 2020 11:03 pm hello follows a functional example tested with postgresql-9.1.1-1-windows version, install and set password 123456
Thank you very much for your help. I´ll try your sample.


Best regards,

Salamandra, Brazil

Re: PostgreSql Libs not ready yet ?

Posted: Fri Jul 17, 2020 2:19 am
by AUGE_OHR
hi,

thx for your Tip.

Code: Select all

   for nPos:=1 to len(aTable)
      doMethod("Main", "Grid_1", "ADDITEM", aTable[nPos])
to transfer Result-Set into Array is the normal way
but what about "RDD" as you have to modify your Code.

---

PGRDD.PRG was from harbour v1.x and not include in harbour v3.x any more
as edk found out DbStruct() give Type "U" what Debugger show.

i have check Type and foundout that all is OK ...

Code: Select all

   FOR EACH aFieldStruct IN aStruct
       ...
       cType := aFieldStruct[ DBS_TYPE ]
       IF VALTYPE( cType ) = "U"
         aField[ UR_FI_TYPE ]  := "C"
       ELSE
         aField[ UR_FI_TYPE ]  := cType
       ENDIF
       ...
       UR_SUPER_ADDFIELD( nWA, aField )
   NEXT       
   /* Call SUPER OPEN to finish allocating work area (f.e.: alias settings) */
   nResult := UR_SUPER_OPEN( nWA, aOpenInfo )
RETURN nResult
USRRDD01.JPG
USRRDD01.JPG (97.86 KiB) Viewed 2940 times
as you see i try GO TOP and other "navigation". it does not give Error :D

i don´t understand how USRRDD work but i think we have to go that way to made it easy

Re: PostgreSql Libs not ready yet ?

Posted: Fri Jul 17, 2020 7:22 am
by dragancesu
DBF vs MySQL / PostgreSQL / Oracle is a big difference and it would really be ideal not to rewrite the program (to work as with dbf) but it's not like that

At work i use oracle and the attempt to work with hmg failed
PostgreSQL is in some ways more similar to oracle than other databases, although mariadb gets some features of oracle database (plsql)

Sqlite works but not for serious work (single user)

My experience with mysql is good, but the program needs a little rewrite to work properly, rdd is a nice thing but ... not for serious work

Simply, make a sql query and send the result to a grid, which in my opinion is a winning combination

Re: PostgreSql Libs not ready yet ?

Posted: Sun Jul 19, 2020 9:40 pm
by AUGE_OHR
hi,

have try to "change" Field Type

Code: Select all

CASE cType = "C"
   aField[ UR_FI_TYPE ]  := HB_FT_STRING
or

Code: Select all

CASE cType = "C"
   aField[ UR_FI_TYPE ]  := ASC("C")-64
both are Number but i get "some" Result
Num_Type.JPG
Num_Type.JPG (16.82 KiB) Viewed 2859 times
but Type still does not match. :cry:
searching for any other Idea :idea:

Re: PostgreSql Libs not ready yet ?

Posted: Sun Jul 19, 2020 10:08 pm
by AUGE_OHR
hi,

that is what i get with Number instead of "C","M","N","D","L"

Code: Select all

1	C:BEU
2	L
3	D
4	N:+	
5	F:+
6	I:+
7	B:+
8	T
9	@
10	=
11	^
12	+:+
13	Y
14	Z
15	Q:BEU
16	M:BEU
17	V:BEU
18	P
19	W
20	G
above 20 it is "U"

Question : what is ":BEU" :idea:

Re: PostgreSql Libs not ready yet ?

Posted: Sun Jul 26, 2020 8:49 pm
by AUGE_OHR
hi,

have try to ask harbour Developer an got this Answer
> Question : is PGRDD still valid ?

You seem to request support for a module that was deleted ten years ago.
Please check changelog.txt before posting.

2010-11-21 20:42 UTC+0100 Viktor Szakats (vszakats.net/harbour)
* contrib/hbpgsql/postgres.c
+ Added PQPREPARE(), PQEXECPREPARED(). Based on code donated by
Lorenzo Fiorini. Modified to compile with current Harbour,
changed parameter handling and error checking, and changed
to return GC collected result pointer. (I didn't make any
tests, so pls do)

* contrib/hbpgsql/hbpgsql.hbp
- contrib/hbpgsql/pgrdd.prg
- contrib/hbpgsql/tests/tstpgrdd.prg
- Deleted experimental USRRDD for PGSQL.

Regards,
Klas
so no RDD for PostgreSQL ... or is there other Way :idea:

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 11:32 am
by mol
Hi!
Sample working fine with postgresql.
But I want to save pictures and .pdfs into database.
Did anybody realize that?
in Postgresql we have BYTEA type which looks OK for it. But,, how to send content of file to server?

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 2:17 pm
by serge_girard
Marek,

I store large files (EXE, PDF, DOCX) in SQL database (type longblob) with this function:

Code: Select all

cEXE_File   := File_To_Buff("'C:\test\test.exe" ) // something large

cQuery1	:= " INSERT INTO TABLE " 
cQuery1	+= " (F1, F2, EXE_FILE)"  
cQuery1	+= " VALUES( "  
cQuery1  +=	" '" + xNR2    + "', "   
cQuery1  +=	" 'BETOZPDF', "
cQuery1  +=	" '" + cEXE_File       + "') "   
cQuery1	:= dbo:Query( cQuery1 )

IF cQuery1:NetErr()		
   ?  PROCNAME(), cQuery1:ErrOR() 
ENDIF




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


fh := FOPEN(cFile_in,0)

IF fh > -1
   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)

Is this what you want?

Serge

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 3:36 pm
by AUGE_OHR
hi Mol,

i have not made it under harbour but under Xbase++
as you say i use Type "bytea" for Image and convert it to HEX using "cBin2Hex()"

not sure what under harbour can be use to convert a "String" into "HEX" and back

Code: Select all

   CASE aStrut[ i, DBS_TYPE ] = 'M'
      // if you have Bitmap in Memo
      //
      IF ::lBlob = .T.
         cIns += " '\x" + cBin2Hex( FIELDGET( i ) ) + "',"
         lUseBlob := .T.
      ELSE
         IF ::lANSI = .T.
            cIns += " '" + STRTRAN( ::OEM_ANSI( FIELDGET( i ) ), "'", '"' ) + "',"
         ELSE
            cIns += " '" + STRTRAN( FIELDGET( i ), "'", '"' ) + "',"
         ENDIF
to "show" Image i use "cHex2Bin()"

Code: Select all

FUNCTION ShowBMPFunc( cBuffer )

   // get rid of "\x" 
   IF SUBSTR( cBuffer, 1, 2 ) = "\x"
      cBuffer := SUBSTR( cBuffer, 3, LEN( cBuffer ) - 2 )
   ENDIF

   oBMP := XBPBITMAP() :new() :create( oPS )
   // Hex to Bin Format using ot4xb
   oBMP:setBuffer( cHex2Bin( cBuffer ) )

   // "paint" Image
   oDlg:drawingarea:paint := { | aRect, uNIL, oSelf | ;
                               oBMP:draw( oPS, { 0, 0, aRect[ 3 ], aRect[ 4 ] }, ;
                               { 0, 0, oBMP:xSize, oBMP:ySize },, ;
                               GRA_BLT_BBO_IGNORE ) }