Page 3 of 4

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 5:47 pm
by mol
I'll try both solutions after backing home.
If I use cbin2hex function I'll get buffer bigger two times, am I right?

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 7:08 pm
by mol
Hi Serge!
Are you using postgresql?
I've declare field as ByteA, but I can't put content of my file.
As I see, error is: invalid byte sentence dor encoding UTF8
Why does it try encoding for byte orinted field?
What's going on?

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 7:54 pm
by AUGE_OHR
hi Mol,
mol wrote: Thu Aug 25, 2022 5:47 pm If I use cbin2hex function I'll get buffer bigger two times, am I right?
em , äh ... have never test LEN()

Re: PostgreSql Libs not ready yet ?

Posted: Thu Aug 25, 2022 8:15 pm
by mol

Code: Select all

cQuery := "CREATE TABLE tab_test("
	cQuery += "     file VARCHAR(40), "
	cQuery += "     content BYTEA )"
	oQuery := oServer:Query(cQuery)
Is it something wrong with creating such a table?
Why can't I put binary content to field content, after translations:

Code: Select all

cBufor   :=   STRTRAN(cBufor, CHR(92), "\134")
cBufor   :=   STRTRAN(cBufor, CHR(0),  "\000")
cBufor   :=   STRTRAN(cBufor, CHR(39), "\047")	
cBufor   :=   STRTRAN(cBufor, CHR(34), "\042")	

Re: PostgreSql Libs not ready yet ?

Posted: Fri Aug 26, 2022 12:16 am
by AUGE_OHR
hi Mol,

try this

Code: Select all

   cQuery := "CREATE TABLE " + xtab + " ( "

   aStrut := DBSTRUCT()
   FOR i = 1 TO LEN( aStrut )
      cQuery += aStrut[ i, DBS_NAME ]
      DO CASE
         CASE aStrut[ i, DBS_TYPE ] = "C"
            cQuery += " character(" + ALLTRIM( STR( aStrut[ i, DBS_LEN ] ) ) + "), "
         CASE aStrut[ i, DBS_TYPE ] = "N"
            cQuery += " numeric(" + ALLTRIM( STR( aStrut[ i, DBS_LEN ] ) ) + ',' + ALLTRIM( STR( aStrut[ i, DBS_DEC ] ) ) + "), "
         CASE aStrut[ i, DBS_TYPE ] = "D"
            cQuery += " date, "
         CASE aStrut[ i, DBS_TYPE ] = "L"
            cQuery += " boolean, "

         CASE aStrut[ i, DBS_TYPE ] = "M"
            IF ::lBlob = .T.
               cQuery += " bytea, "
            ELSE
               cQuery += " text, "
            ENDIF
      ENDCASE
   NEXT
   // add for internal use
   cQuery += " __deleted    boolean NOT NULL DEFAULT false, "
   cQuery += " __record     serial  NOT NULL, "

   // create PRIMARY KEY
   cQuery += " CONSTRAINT " + xtab + "_pkey PRIMARY KEY (__record)"
   cQuery += " )"   

   oPG:exec( cQuery )                                                 // create Table
   IF ResultStatus( oPG, oMain )
   ELSE
      // if fail
   ENDIF
to INSERT Data i use this

Code: Select all

   // for every Record
   cPreText := "INSERT INTO " + xtab + " VALUES("

   GO TOP
   DO WHILE .NOT. EOF()
      cIns += cPreText
      i = 1
      FOR i = 1 TO LEN( aStrut )
         DO CASE
            CASE aStrut[ i, DBS_TYPE ] = "C"
            CASE aStrut[ i, DBS_TYPE ] = "N"
            CASE aStrut[ i, DBS_TYPE ] = "D"
            CASE aStrut[ i, DBS_TYPE ] = "L"
            CASE aStrut[ i, DBS_TYPE ] = 'M'
               // if you have Bitmap in Memo
               IF ::lBlob = .T.
                  cIns += " '\x" + cBin2Hex( FIELDGET( i ) ) + "',"
               ELSE
                  cIns += " '" + STRTRAN( FIELDGET( i ), "'", '"' ) + "',"
               ENDIF

         ENDCASE
      NEXT
      // add "__deleted" default
      cIns += "false,"                                             // "__deleted"

      // use nextval() for Sequence !
      cIns += "nextval('" + xtab + "___record_seq')" + ","         // use nextval()

      oPG:exec( cIns )                                          // now send Query
      IF ResultStatus( oPG, oMain )                             // get Result Status
         // Reset
         cIns := ""
      ELSE
         // if fail
      ENDIF

      SKIP
   ENDDO

   IF !EMPTY( cIns )
      oPG:exec( cIns )                                                // send Rest 
   ENDIF

Re: PostgreSql Libs not ready yet ?

Posted: Fri Aug 26, 2022 5:35 am
by mol
I've inserted timestamp to BYTEA kolumn and unde HeidiSQL I can see that pg server converted it to hex:
20220825 22:10:43 \x32303232303832352032323a31303a3433
So for what I have to do conversion by my side? It should be converted for TEXT type column, not for BYTEA.
As I can see, stored value is much more longer

Re: PostgreSql Libs not ready yet ?

Posted: Fri Aug 26, 2022 6:32 am
by serge_girard
Marek,

I don't use postgresql.
MySQL-HeidiSQL is what I use...

But it can't be that much different?

Serge

Re: PostgreSql Libs not ready yet ?

Posted: Fri Aug 26, 2022 9:06 am
by mol
Another behavior in Microsoft SQL Server and another in Postgresql
I'm on the beginning, time to choose right server. I'm doing tests.
I didn't do anything with Postgresql

Time to start weekend I will be back on Monday

Re: PostgreSql Libs not ready yet ?

Posted: Fri Aug 26, 2022 7:05 pm
by AUGE_OHR
hi Mol,

ask your Customer if he is willing to pay for Microsoft SQL Server or use Postgresql which is free

i have begin to use PostgreSQL "native", using LibPQ.DLL, when Alaska present PgDBE (like RDD) for Xbase++
the Idea was to have a "replacement" which use ISAM Style under SQL ...

but the Concept of PgDBE have a "big Overhead" so it become "slow" ...

---
I can see that pg server converted it to hex:
20220825 22:10:43 \x32303232303832352032323a31303a3433
did you "see" \x @Start ?
this is exact what i wrote in my CODE
So for what I have to do conversion by my side?
you "just" need to "add" \x when INSERT a BLOB, in HEX Format (cBin2Hex()), and "remove" \x before convert HEX back to BIN (cHex2Bin())
As I can see, stored value is much more longer
i don´t "see" a Problem with "Space" when using SQL

p.s. i found out that LibPQ.DLL of PostgreSQL v14 can work without "other" *.DLL (when SSL is not used)
when need 32 Bit LibPQ.DLL i recommend to download PgAdmin 4 which are available as 32 Bit (PostgreSQL Server only 64 Bit)

Re: PostgreSql Libs not ready yet ?

Posted: Mon Aug 29, 2022 7:31 pm
by mol
Hi Jimmy! Where can I find cBin2Hex function?