Request : function GetSerialCol()

Request : function GetSerialCol()

Postby Jimmy » Sun Sep 24, 2023 9:20 pm

hi,

in c:\fwh\source\function\pgsuport.prg we have
Code: Select all  Expand view  RUN
#ifdef UNUSEDFUNCS
STATIC function GetSerialCol

can you please "enable" it

i need it for PostgreSQL PRIMARY KEY of Table made by Alaska
Code: Select all  Expand view  RUN
cQuery += " CONSTRAINT " + cTable + "_pkey PRIMARY KEY (__record)"

it will use
Code: Select all  Expand view  RUN
     // use nextval() for Sequence !
      cIns += "nextval('" + cTable + "___record_seq')" + ","

to "increment" FIELD "__record" when INSERT new Record
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Request : function GetSerialCol()

Postby nageswaragunupudi » Mon Sep 25, 2023 4:24 am

You may comment out #ifdef and #endif in your copy and test.
Regards

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

Re: Request : function GetSerialCol()

Postby Jimmy » Mon Sep 25, 2023 1:01 pm

hi,
nageswaragunupudi wrote:You may comment out #ifdef and #endif in your copy and test.

i do have include Copy of PGSUPORT.PRG and it work like i need

p.s. have also include copy of METHOD SavePQQ() CLASS TDataRow to work with GetSerialCol()
as currval() is NOT the right Way (for Alaska Concept) i have to re-write CODE for APPEND a new Record in Table
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Request : function GetSerialCol()

Postby nageswaragunupudi » Tue Sep 26, 2023 3:59 am

If you want to change the logic of the method SavePQQ(), please do this way.
Code: Select all  Expand view  RUN
oRec := TDataRow():New( oRs, [lAppend] )
oRec:bSave := { |oRec| MySavePQQ( oRec ) }
oRec:Edit()


Please copy the method SavePQQ() to a separate function "MySavePQQ( oRec )" in your program and make the changes you need. This codeblock may return .t. if saved or .f. if not.
Regards

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

Re: Request : function GetSerialCol()

Postby Jimmy » Tue Sep 26, 2023 6:40 am

hi,

thx for Answer
nageswaragunupudi wrote:Please copy the method SavePQQ() to a separate function "MySavePQQ( oRec )" in your program and make the changes you need.


i can use your Sample with XBROWSE and :bLDblClick for "save"
ok, i will try that Way

---

instead of XBROWSER i have try
Code: Select all  Expand view  RUN
  oRs := oPGU:Query( "select * from " + cTable )
*   XBROWSER oRs TITLE cTable AUTOSORT FASTEDIT

   @ nBhight,  2 XBROWSE oBrw SIZE nWidth - 20, nHeight - 90 PIXEL OF oWnd ;
           RECORDSET oRs AUTOSORT FASTEDIT ;
           AUTOCOLS ;
           CELL LINES NOBORDER UPDATE ;
           FONT oFontDefault COLOR BFcolor, BGcolor

   oBrw:bLDblClick := { || MyTDataRow( oRs, .T. ) }

   oBrw:CreateFromCode()


Code: Select all  Expand view  RUN
PROCEDURE MyTDataRow( oRs, lAppend )
LOCAL oRec
DEFAULT lAppend := .F.

   oRec := TDataRow():New( oRs, lAppend )
   oRec:bSave :=  { |oRec| MySavePQQ( oRec ) }
   oRec:Edit()
RETURN

i got Dialog with "edit" Control but all are empty ... :shock:
i have try
Code: Select all  Expand view  RUN
     oBrw:bLDblClick := { |oRec| MyTDataRow( oRec, .T. ) }

but this give me "Enter : 1-line-edit" ... :(

what do i miss :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Request : function GetSerialCol()

Postby nageswaragunupudi » Tue Sep 26, 2023 12:13 pm

Advise to write the code in these lines:
Code: Select all  Expand view  RUN
DEFINE BUTTONBAR oBar OF oWnd SIZE 80,32

@ 50,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oWnd ;
   DATASOURCE oRs AUTOCOLS AUTOSORT ;
   CELL LINES NOBORDER FASTEDIT
   
WITH OBJECT oBrw
   :nEditTypes := EDIT_GET
   :bDataRow   := < |brw,cFieldList,lNew|
         local oRec  := TDataRow():New( oRs, cFieldList, lNew )
         oRec:bSave  := { |oRec| MySavePQQ( oRec ) }
         return oRec
         >
   :CreateFromCode()
END

DEFINE BUTTON OF oBar PROMPT "AddNew" ACTION oBrw:EditSourc( .t. )
DEFINE BUTTON OF oBar PROMPT "Edit"   ACTION oBrw:EditSource()

ACTIVATE WINDOW oWnd

//----------------------------------------------------------------------------//

function MySavePQQ( Self )

   local lAppend  := ( ::RecNo == 0 )
   local oQry  := ::uSource
   local aModi := ::aModiData
   local aKey  := {}
   local aSave := {}
   local cSeq, nCurVal
   local n, v, nFld, cSql, uVal, cWhere, nRows, nRow
   local lRefresh    := .f.

   for n := 1 to Len( ::aStructPG )
      if ::aStructPG[ n, 10 ] == "PRI" .and. ;
         oQry:TableName == ::aStructPG[ n, 7 ]
         if cSeq == nil .and. ::aStructPG[ n, 2 ] == '+'
            cSeq     := ::aStructPG[ n, 9 ]
         endif
         if ValType( ::aData[ n, 2 ] ) == 'C'
            AAdd( aKey, { n, ::aStructPG[ n, 8 ], TRIM( ::aOrg[ n, 2 ] ), TRIM( ::aData[ n, 2 ] ) } )
         else
            AAdd( aKey, { n, ::aStructPG[ n, 8 ], ::aOrg[ n, 2 ], ::aData[ n, 2 ] } )
         endif
      endif
   next

   if Empty( aKey )
      return .t.
   endif

   for n := 1 to Len ( ::aModiData )
      nFld     := ::aModiData[ n, 3 ]
      uVal     := ::aModiData[ n, 2 ]
      if ValType( uVal ) == 'C'
         uVal  := Trim( uVal )
      endif
      AAdd( aSave, { ::aStructPG[ nFld, 8 ], uVal } )
   next

   if Empty( aSave )
      return .t.
   endif

   if lAppend
      cSql  := "INSERT INTO " + oQry:Schema + "." + oQry:TableName + " ( "
      cSql  += FW_ArrayAsList( ArrTranspose( aSave )[ 1 ] )
      cSql  += " ) VALUES "
      cSql  += FW_ValToSQL( ArrTranspose( aSave )[ 2 ], nil, "PG" )
   else
      cSql  := "UPDATE " + oQry:Schema + "." + oQry:TableName
      for n := 1 to Len( aSave )
         if n == 1
            cSql  += " SET "
         else
            cSql  += ", "
         endif
         cSql  += aSave[ n, 1 ] + " = " + FW_ValToSQL( aSave[ n, 2 ],, "PG" )
      next

      for n := 1 to Len( aKey )
         if n == 1
            cSql  += " WHERE "
         else
            cSql  += " AND "
         endif
         cSql  += aKey[ n, 2 ] + " = "  + FW_ValToSQL( aKey[ n, 3 ] )
      next
   endif

   FWPG_Execute( oQry, cSql )
   if lAppend .and. !Empty( cSeq )
      nCurVal  := FWPG_Execute( oQry, "SELECT currval( '" + cSeq + "' )" )[ 1, 1 ]
   endif
   oQry:Refresh()
   // Reposition record
   if lAppend
      n     := aKey[ 1, 1 ]
      if !Empty( nCurVal )
         v  := nCurVal
      else
         v  := aKey[ 1, 4 ]
      endif
      oQry:GoTo( oQry:LastRec() )
      FWPG_GoToKeyVal( oQry, n, v )
      lRefresh := .t.
   else
      n     := aKey[ 1, 1 ]
      v     := aKey[ 1, 4 ]
      if ! ( oQry:FieldGet( n ) == v )
         FWPG_GoToKeyVal( oQry, n, v )
         lRefresh := .t.
      endif
   endif

   ::ReadPQQ( nil, .f., .t. )
   if ::oBrw != nil
      if lRefresh
         ::oBrw:Refresh()
      else
         ::oBrw:RefreshCurrent()
      endif
   endif

return .t.

//----------------------------------------------------------------------------//
 

Make your changes in the function MySavePQQ()
Regards

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

Re: Request : function GetSerialCol()

Postby Jimmy » Wed Sep 27, 2023 4:15 am

hi,

thx for your Advice

"where" can i read more about Construction like this :?:

---

i mean : what if People have a Accident and can not help any more ...
special XBROWSE are so "big" so it is almost impossible to "understand" all the CODE when have no Help File
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Request : function GetSerialCol()

Postby Jimmy » Wed Sep 27, 2023 7:46 am

hi,

thx for Answer.

i have use the CODE and got Data from Controls :)
but when try to "save" i got Error
Error description: Error BASE/42 Scope violation (protected): TDATAROW:READPQQ

Image

Question : how to "disable" those 5 Button on left Side of "edit" ( which make no Sense when "edit" ) :?:

---

but CODE still does not work as it does not "recognize" PRIMARY KEY made by Xbase++ Concept
Image

when use Alaska PgDBE PRIMARY KEY, which point to "internal" FIELD __record, never can be 0
this why i need function GetSerialCol() which work right with Alaska Concept

p.s. not sure if we need :READPQQ() as Bro:Refresh() will show right Result

---

i wonder about "self" as Parameter ... never saw it before, GREAT :)

---

Code: Select all  Expand view  RUN
  :nEditTypes := EDIT_GET

have no Effect in Sample (can edit but does not save)

Question : how can i redirect Dblclick to "edit" :?:

have try
Code: Select all  Expand view  RUN
   :bLDblClick := :EditSource()

but it gave me Error

----

when press Button "add new" it crash
Error description: Error BASE/1004 Message not found: TXBROWSE:EDITSOURC

Stack Calls
===========
Called from: .\source\function\HARBOUR.PRG => _CLSSETERROR( 247 )
Called from: .\XBROWSE.PRG => TXBROWSE:EDITSOURC( 11840 )
Called from: .\FWPGU.PRG => (b)SHOWTABLE( 1167 )


---

will continue to work on it ...
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Request : function GetSerialCol()

Postby Jimmy » Wed Sep 27, 2023 3:50 pm

hi

i can add new Record, it was a Typo :roll:

---

i can use bLDblClick when NOT set nEditTypes
Code: Select all  Expand view  RUN
*      :nEditTypes := EDIT_GET
      :bLDblClick := { || oBrw:EditSource() }

it must before :bDataRow := Codeblock
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany


Return to FiveWin for Harbour/xHarbour

Who is online

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