Subject Posting a second record to a Dataset linked to a TIB_Grid
Author Roberto Freitas
Hi Helen, as you asked:

IB_QueryConta
KeyLinks
Conta.cct_ciireg
Conta.cct_ident
(these 2 fields are table primary key)
RequestLive property is TRUE

This is from TIB_Monitor:

SELECT * FROM Conta WHERE
cct_ciireg = '10010001'
AND cct_mae = 1004
ORDER BY cct_conta ASC

PLAN SORT ((CONTA INDEX (IX_CONTA2)))

FIELDS = [ Version 1 SQLd 13 SQLn 30
CONTA.CCT_CIIREG[CCT_CIIREG] = <NIL>
CONTA.CCT_IDENT = <NIL>
CONTA.CCT_MAE = <NIL>
CONTA.CCT_TIPO = <NIL>
CONTA.CCT_CONTA = <NIL>
CONTA.CCT_CUSCOD = <NIL>
CONTA.CCT_TITULO = <NIL>
CONTA.CCT_CRIACAO = <NIL>
CONTA.CCT_GRAU = <NIL>
CONTA.CCT_ORDEM = <NIL>
CONTA.CCT_RATEIO = <NIL>
CONTA.CCT_CHAT = <NIL>
CONTA.CCT_CHAP = <NIL> ]


INSERT INTO CONTA
( CCT_CIIREG
, CCT_IDENT
, CCT_MAE
, CCT_CONTA
, CCT_TITULO
, CCT_TIPO
, CCT_CUSCOD
, CCT_ORDEM
, CCT_RATEIO
, CCT_CHAT
, CCT_CHAP)
VALUES
( ? /* CONTA.CCT_CIIREG */
, ? /* CONTA.CCT_IDENT */
, ? /* CONTA.CCT_MAE */
, ? /* CONTA.CCT_CONTA */
, ? /* CONTA.CCT_TITULO */
, ? /* CONTA.CCT_TIPO */
, ? /* CONTA.CCT_CUSCOD */
, ? /* CONTA.CCT_ORDEM */
, ? /* CONTA.CCT_RATEIO */
, ? /* CONTA.CCT_CHAT */
, ? /* CONTA.CCT_CHAP */ )

FIELDS = [ Version 1 SQLd 0 SQLn 30 ]
----*/
/*---
[ 05/10/2005 17:23:59 ]
EXECUTE STATEMENT
TR_HANDLE = 14228092
STMT_HANDLE = 14226772
PARAMS = [ Version 1 SQLd 11 SQLn 11
CONTA.CCT_CIIREG[CCT_CIIREG] = '10010001'
CONTA.CCT_IDENT = 0
CONTA.CCT_MAE = 1004
CONTA.CCT_CONTA = '110101003'
CONTA.CCT_TITULO = 'teste1'
CONTA.CCT_TIPO = 'A'
CONTA.CCT_CUSCOD = <NULL>
CONTA.CCT_ORDEM = 0
CONTA.CCT_RATEIO = 0
CONTA.CCT_CHAT = 0
CONTA.CCT_CHAP = 0 ]

ERRCODE = 335544347
----*/
/*---
[ 05/10/2005 17:23:59 ]
INTERPRET BUFFER =

ERRCODE = 61
----*/
/*---
[ 05/10/2005 17:23:59 ]
INTERPRET BUFFER = validation error for column CCT_CRIACAO,
value "*** null ***"

ERRCODE = -1
----*/

I did not construct the InsertSQL, so I suppose IBO did it.
As you can note, fields CCT_CRIACAO and CCT_GRAU are present in
SELECT clause, but are NOT present in INSERT clause, (CCT_GRAU is
allowed Null in DataBase) but if I watch at BeforePost event their
values are:

FormatDateTime('yyyy-mm-dd hh:nn:ss', FieldByName
('cct_criacao').AsDateTime) = '2005-10-05 18:04:34'
FieldByName('cct_grau').AsInteger = 5

I did no changes on code, so I dont't know why the original problem
was transfered from CCT_CIIREG to CCT_CRIACAO, but it's still the
same problem.

I hope there's enough information for your analisys. Great thanks,

Roberto


--- In IBObjects@yahoogroups.com, Helen Borrie <helebor@t...> wrote:
> At 06:26 PM 4/10/2005 +0000, you wrote:
> >Hi Helen,
> >Now I remember my original problem that persists for weeks and was
> >posted before.
> >Take a look on my original question:
> >
> >I am using a TIB_Grid linked to a TIB_DataSource and a TIB_Query.
> >I have this code at IB_QueryContaAfterInsert event:
> >with IB_QueryConta do
> >begin
> >...
> >FieldByName('cct_ciireg').AsString := Gl_ciireg_f;
> >...
> >end;
> >Im this case, Gl_ciireg_f = '10010001'
>
> If 1) the field 'cct_ciireg' is present in the SELECT statement
>
> and
>
> 2) you have correct keylinks
>
> an
>
> 3) the dataset's RequestLive property is set to True
>
> then this assignment will work.
>
> >For a new record, the user types values for other fields on the
> >TIB_Grid. Field cct_ciireg is not visible on the grid, so user
cannot
> >change it.
> >I checked that the code above actually executes.
> >I watched FieldByName('cct_ciireg').AsString in 2 different places:
> >at end of IB_QueryContaAfterInsert event and
> >at end of IB_QueryContaBeforePost event
> >In both places, the value is correct = '10010001'
> >Although, when posting record, I got this ISC Error Message:
> >ISC ERROR CODE: 335544347
> >validation error for column CCT_CIIREG, value "***null***"
> >
> >Looking at TIB_Monitor, the real Insert statement doesn't have
field
> >cct_ciireg, but only fields that are on the TIB_Grid (cct_ciireg is
> >one of the fields whose value is assigned on code, not on grid,
> >because it is in the Query but not in the grid):
>
>
> >These are the strings from TIB_Monitor:
> >
> >INSERT INTO CONTA
> >( CCT_CONTA
> >, CCT_TITULO
> >, CCT_TIPO
> >, CCT_CUSCOD
> >, CCT_ORDEM
> >, CCT_RATEIO)
> >VALUES
> >( ? /* CONTA.CCT_CONTA */
> >, ? /* CONTA.CCT_TITULO */
> >, ? /* CONTA.CCT_TIPO */
> >, ? /* CONTA.CCT_CUSCOD */
> >, ? /* CONTA.CCT_ORDEM */
> >, ? /* CONTA.CCT_RATEIO */ )
>
> OK, if CCT_CIIREG really is present in the dataset, then this
InsertSQL was
> not constructed by IBO.
>
> >FIELDS = [ Version 1 SQLd 0 SQLn 30 ]
> >----*/
> >/*---
> >[ 16/09/2005 07:02:11 ]
> >EXECUTE STATEMENT
> >TR_HANDLE = 14164468
> >STMT_HANDLE = 14166400
> >PARAMS = [ Version 1 SQLd 6 SQLn 6
> >CONTA.CCT_CONTA = '110103018'
> >CONTA.CCT_TITULO = 'teste'
> >CONTA.CCT_TIPO = 'A'
> >CONTA.CCT_CUSCOD = 'teste'
> >CONTA.CCT_ORDEM = 0
> >CONTA.CCT_RATEIO = 0 ]
> >
> >ERRCODE = 335544347
> >----*/
> >/*---
> >[ 16/09/2005 07:02:11 ]
> >INTERPRET BUFFER =
> >
> >ERRCODE = 60
> >----*/
> >/*---
> >[ 16/09/2005 07:02:11 ]
> >INTERPRET BUFFER = validation error for column CCT_CIIREG,
value "***
> >null ***"
> >
> >Submiting these questions on Forum before, somebody suggests to
fill
> >in the IB_Query Insert property (at end of BeforePost event) with
the
> >statement I want to submit to the server.
>
> That's not correct advice for the problem as you describe it here.
>
> If you intend to use the Insert method of the dataset, you need the
> InsertSQL to be present before the SELECT statement is prepared.
As I have
> explained before, for a simple SELECT statement, IBO does this
> automatically, as long as you have taken proper care with
KeyLinks. If you
> need to use custom SQL (which does not appear to be the case here)
>
> Having a field's Visible property set to True does NOT prevent it
being
> assigned to or, more broadly, you are mistaken if you think that
the
> InsertSQL is constructed from the fields that are visible in the
grid.
>
> I want to see the exact SELECT statement that is used to get the
> dataset. From there, I can show you what you need to do to make
this
> internal assignment. We are not talking about anything
complicated. The
> corrections I did to your online example are all you need to assign
a value
> to a hidden field.
>
> Helen