GRID control and RLOCK()

Moderator: Rathinagiri

User avatar
raumi75
Posts: 135
Joined: Wed Dec 17, 2008 2:31 am
Location: Lünen, Germany
Contact:

GRID control and RLOCK()

Post by raumi75 »

Hello Roberto,

I use the GRID control with PGRDD (Postgresql RDD). Unfortunately, pgrdd has a flaw: It does not support RLOCK()

It is usually no problem at all. My program runs fine, without rlock.

This is not an hmg-bug, but it causes some problems when saving data in a data-bound grid.

When the grid-control saves data, it tries to rlock the table (h_grid.prg in line 2098).

I tried to come up with a quick fix to the problem. and added IF RDDNAME() # "PGRDD". I know, it is very ugly, but does the trick. Postgresql does not need to be locked explicitly, so there should be no harm done.

So line 2098 of h_grid.prg looks like this:

Code: Select all

* If unable to lock return
   if RDDNAME() # "PGRDD" && raumi75
      If Rlock() == .F.
         MsgExclamation(_HMG_SYSDATA [ 136 ][9],_HMG_SYSDATA [ 136 ][10])
         &cRecordSource->(dbgoto(nRecNo))
         return .f.
      endif
   endif && raumi75
and line 2112 now looks like this.

Code: Select all

   * Unlock
   if RDDNAME() # "PGRDD" && raumi75
   	&cRecordSource->(dbrUnlock(&cRecordSource->(recno())))
   endif && raumi75
It worked and my data gets saved.

But now I ran into the next problem:

The function DataGridRefresh(index) loads an array of values:

Code: Select all

aValue := _GetValue (  ,  ,  index )
This does not work. The value aValue [1] is empty.

I would really appreciate your help. I am stuck.
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: GRID control and RLOCK()

Post by Roberto Lopez »

raumi75 wrote:Hello Roberto,

I use the GRID control with PGRDD (Postgresql RDD). Unfortunately, pgrdd has a flaw: It does not support RLOCK()
<...>
Thanks for the report.

I've started to work on both issues.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: GRID control and RLOCK()

Post by Roberto Lopez »

raumi75 wrote: <...>
But now I ran into the next problem:

The function DataGridRefresh(index) loads an array of values:

Code: Select all

aValue := _GetValue (  ,  ,  index )
This does not work. The value aValue [1] is empty.

I would really appreciate your help. I am stuck.
I've fixed the PGRDD problem (I've was already fixed for SQLMIX) but I've not found any problem with getting grid value.

I've modified Grid.25 sample and added the following line to the menu:

Code: Select all

				ITEM 'Get Value'				ACTION ( aValue := Form_1.Grid_1.Value , MsgInfo( Str( aValue [1] ) + ' , ' + Str( aValue [2] ) ) )
And it works fine.

Please, let me know in which context it fails.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
raumi75
Posts: 135
Joined: Wed Dec 17, 2008 2:31 am
Location: Lünen, Germany
Contact:

Re: GRID control and RLOCK()

Post by raumi75 »

Hello Roberto,

thank you for the quick reply.

Getting a value from the grid is no problem. I checked it in the sample and in my application.

The problem seems to be in h_grid.prg around line 2165.

Code: Select all

*****************
Function DataGridRefresh(index)
******

Static cRecordSource := ''
Static aColumnFields := {}

	cRecordSource	:= _HMG_SYSDATA [ 40 ] [ index ] [ 10 ]
	aColumnFields	:= _HMG_SYSDATA [ 40 ] [ index ] [ 11 ]

	nHandle	:= _HMG_SYSDATA [ 3 ] [ index ] 

	aValue := _GetValue (  ,  ,  index )

	nInitialLogicalPos := aValue [1]
   
* Here comes the problem:
   if empty(aValue [1])
       msgbox("aValue [1] is empty")
   endif
   
	nDeltaRow := LISTVIEW_GETTOPINDEX ( nHandle ) - aValue [1] + 1 

The function SaveDataGridField calls DataGridRefresh whenever "initial logical position is different from Final logical position." It might be a rare case with other RDDs, but I get this condtion everytime. As you can see, I inserted the msgbox-Dialog, to see if aValue is empty.

Hope this helps a little :-)

Raumi
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: GRID control and RLOCK()

Post by Roberto Lopez »

raumi75 wrote:Hello Roberto,

thank you for the quick reply.

Getting a value from the grid is no problem. I checked it in the sample and in my application.

The problem seems to be in h_grid.prg around line 2165.
I'm very sorry, but I guess that I'm not understanding...

Please, send me a complete sample showing the situation when the value property returns a wrong value.

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
raumi75
Posts: 135
Joined: Wed Dec 17, 2008 2:31 am
Location: Lünen, Germany
Contact:

Re: GRID control and RLOCK()

Post by raumi75 »

Roberto Lopez wrote: I'm very sorry, but I guess that I'm not understanding...

Please, send me a complete sample showing the situation when the value property returns a wrong value.

TIA.
I feel terrible, that I can't explain it easier. I will try to show my problem with a sample.

Given: I use a table called test. It has the columns garken (C), eigenschaft (C), wert (C) and id (N).

I took GRID.30 and modified it to use a postgresql-server. It works fine, when I use the dbf-table. But when I use a postgresql-table, the sample looks like this.

Code: Select all

/*
* MiniGUI Virtual Grid Demo
* (c) 2009 Roberto Lopez
*/

* Modified by raumi75 to show problem mit Postgresql

#include "hmg.ch"


#command USE <(db)> [VIA <rdd>] [ALIAS <a>] [<nw: NEW>] ;
            [<ex: EXCLUSIVE>] [<sh: SHARED>] [<ro: READONLY>] ;
            [CODEPAGE <cp>] [CONNECTION <nConn>] [INDEX <(index1)> [, <(indexN)>]] => ;
         dbUseArea( <.nw.>, <rdd>, <(db)>, <(a)>, ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>,  [<cp>], [<nConn>] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]
         
Function Main

   * Postgresql-Connection
   request PGRDD
   nConn := dbpgconnection( "192.168.1.101;databasename;username;password" )
   
	* Dynamic Display

	bdDisplay_1 := { || Upper(This.CellValue) }
	bdDisplay_2 := { || Lower(This.CellValue)  }


	* Grid Column Controls Definitions

	aCtrl_1 := {'TEXTBOX','CHARACTER'}
	aCtrl_2 := {'TEXTBOX','CHARACTER'}


	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 800 ;
		HEIGHT 510 ;
		TITLE 'Hello World!' ;
		MAIN 

		DEFINE MAIN MENU 
			POPUP 'File'
				ITEM 'Append (Alt+A)'				ACTION Form_1.Grid_1.Append
				ITEM 'Save Last Appended Record (Alt+S)'	ACTION Form_1.Grid_1.Save
				ITEM 'Set RecNo'				ACTION Form_1.Grid_1.RecNo := val(InputBox('','')) 
				ITEM 'Get RecNo'				ACTION MsgInfo( Str(Form_1.Grid_1.RecNo) )
				ITEM 'Delete'					ACTION Form_1.Grid_1.Delete
				ITEM 'Recall'					ACTION Form_1.Grid_1.Recall
			END POPUP
		END MENU

      use "SELECT * FROM test WHERE garken = 'VISION    ' ORDER BY id;" alias Test NEW via "pgrdd" connection nConn


		@ 10,10 GRID Grid_1 ;
			WIDTH 770 ;
			HEIGHT 440 ;
			HEADERS {'Column 1','Column 2'} ;
			WIDTHS {140,140};
			EDIT ;
			VALUE { 1 , 1 } ;
			COLUMNCONTROLS { aCtrl_1 , aCtrl_2 } ;
			ROWSOURCE "Test" ;
			COLUMNFIELDS { 'eigenschaft' ,  'wert'} ;
			ALLOWAPPEND  ;
			BUFFERED ;
			ALLOWDELETE ;
			DYNAMICDISPLAY	 { bdDisplay_1 , bdDisplay_2 } ;
		
	END WINDOW

	CENTER WINDOW Form_1

	ACTIVATE WINDOW Form_1

Return
When I run the program, It displays very well. But: When trying to exit a field after editing it, I get the following error:

Code: Select all

Error BASE/1082 Argument error: -

Called from DATAGRIDREFRESH(2176)
Called from SAVEDATAGRIDFIELD(2145)
Called from _HMG_GRIDINPLACEEDITOK(1217)
Called from (b)_HMG_GRIDINPLACEEDIT(794)
Called from _DOCONTROLEVENTPROCEDURE(4919)
Called from EVENTS(563)
Called from _DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(4583)
Called from _HMG_GRIDINPLACEEDIT(963)
Called from EVENTS(2624)
Called from _DOMESSAGELOOP(0)
Called from _ACTIVATEWINDOW(4561)
Called from MAIN(75) 
The line number DATAGRIDREFRESH(2176) is different from your line number, because I fixed the RLOCK()-Postgresql-Bug and added the if empty(aValue [1]) lines which I quoted a few hours ago. It refers to the line

Code: Select all

nDeltaRow := LISTVIEW_GETTOPINDEX ( nHandle ) - aValue [1] + 1 
in your file C:\hmg\SOURCE\h_grid.prg

aValue [1] is empty, so the "- Operation" fails.

I know, I sound confusing and I am sorry for not keeping it simpler.

Thank you for taking the time to listen to me.

Raumi
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: GRID control and RLOCK()

Post by Roberto Lopez »

raumi75 wrote: I feel terrible, that I can't explain it easier. I will try to show my problem with a sample.
<...>
Ok.

I must to recreate the complete environment to test it and try to find a solution.

I'll try to do, but it could take some time...

Apparently the basic problem is that the Postgre RDD is not behaving exactly the same as standard rdds.

If aValue [1] is zero, it could indicate that due to some reason, no cell is selected. Is that the case?

TIA.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
raumi75
Posts: 135
Joined: Wed Dec 17, 2008 2:31 am
Location: Lünen, Germany
Contact:

Re: GRID control and RLOCK()

Post by raumi75 »

Roberto Lopez wrote:
raumi75 wrote: I feel terrible, that I can't explain it easier. I will try to show my problem with a sample.
<...>
Ok.

I must to recreate the complete environment to test it and try to find a solution.

I'll try to do, but it could take some time...

Apparently the basic problem is that the Postgre RDD is not behaving exactly the same as standard rdds.

If aValue [1] is zero, it could indicate that due to some reason, no cell is selected. Is that the case?

TIA.
You are right.

To test your assumption, I added the following lines to DataGridRefresh in h_grid.prg

Code: Select all

msgbox("index: "+str(index)+ "Row: "+str(This.QueryRowIndex)+"Col: "+str(This.QueryColIndex) )
When I rund SAMPLE\GRID30, it returns an index of 7 and the correct Row and Col. But when I run my modified Sample with pgrdd, index is 7, but Row and Col is 0! :-(

I have no explanation, why this happens. Did you see the other post about _GetValue being empty? I am not the only one. Somehow this makes me feel better. ;-)

Raumi
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: GRID control and RLOCK()

Post by Roberto Lopez »

raumi75 wrote:
I have no explanation, why this happens. Did you see the other post about _GetValue being empty? I am not the only one. Somehow this makes me feel better. ;-)

Raumi
Well... I have some explanations now, but not all of them :)

There is, at least, one big problem:

Apparently OrdKeyNo() and OrdKeyGoTo() are not working with PostGre RDD the same way as in standard rdds.

With standard rdds, when no index is active, these functions behaves like recno() and dbgoto(). With Postgre rdd, no.

This is reasonable since this rdd does not support indexes.

The problem is that Grid rely heavily on these functions to work.

Moreover, could be other incompatibilities to solve.

Since it will require lots of coding and tests, I'll delay this fix until 3.0.22.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Re: GRID control and RLOCK()

Post by Roberto Lopez »

Roberto Lopez wrote:
Well... I have some explanations now, but not all of them :)

There is, at least, one big problem:

Apparently OrdKeyNo() and OrdKeyGoTo() are not working with PostGre RDD the same way as in standard rdds.

With standard rdds, when no index is active, these functions behaves like recno() and dbgoto(). With Postgre rdd, no.

This is reasonable since this rdd does not support indexes.

The problem is that Grid rely heavily on these functions to work.

Moreover, could be other incompatibilities to solve.
I've discovered some other problems.

Apparently Postgre RDD does not allow to modify records in the usual way.

I've created a database called 'data1', a table called 'table1' with two columns named 'field1' and 'field2', both type character (32).

When I do the following:

Code: Select all

dbappend()
replace field1 with "John"
replace field2 with "Smith"
It works.

But if I do:

Code: Select all

Go Top
replace field1 with "John"
I obtain the following error message:
PGRDD/3000 Data type error, Cannot insert in a joined table, or unknown error
So, at the moment, I don't know how to modify a record :)

This is the complete code:

Code: Select all

#include "hmg.ch"

#command USE <(db)> [VIA <rdd>] [ALIAS <a>] [<nw: NEW>] ;
            [<ex: EXCLUSIVE>] [<sh: SHARED>] [<ro: READONLY>] ;
            [CODEPAGE <cp>] [CONNECTION <nConn>] [INDEX <(index1)> [, <(indexN)>]] => ;
         dbUseArea( <.nw.>, <rdd>, <(db)>, <(a)>, ;
                    if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>,  [<cp>], [<nConn>] ) ;
         [; dbSetIndex( <(index1)> )] ;
         [; dbSetIndex( <(indexN)> )]
         
Function Main

   * Postgresql-Connection
   request PGRDD
   nConn := dbpgconnection( "127.0.0.1;data1;postgres;1234" )
   
   DEFINE WINDOW Form_1 ;
      AT 0,0 ;
      WIDTH 800 ;
      HEIGHT 510 ;
      TITLE 'Hello World!' ;
      MAIN


      use "SELECT * FROM table1 ;" alias Test NEW via "pgrdd" connection nConn


* This works
	dbappend()
	replace field1 with "John"
	replace field2 with "Simith"


* But attempting to change, fails:

	go top
	replace field1 with "*"	
	dbcommit()

      
   END WINDOW

   CENTER WINDOW Form_1

   ACTIVATE WINDOW Form_1

Return
	
		
Any help is welcome.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
Post Reply