esos metodos no existenten.
oRec := oQry:Record() // returns FW_Record/TDataRow Object
oRec := oQry:Record( .t. ) // returns blank FW_Record/TDataRow objecct
oRow to assign a previously obtained object with GetRowObj to the oRs object and then Save()
oRec:Save()
FUNCTION GetAutoIncrement(cTable,cField)
RETURN oApp:oServer:QueryResult('SELECT MAX('+cField+') FROM ' + cTable) + 1
oRec := oQry:Record(.t.)
oRec:ciudad := "Mercedes (B)"
oRec := oQry:Record(.t.)
oRec:codigo := GetAutoIncrement("ciudades","codigo") // Campo codigo es autoincremental
Error description: Error BASE/39 Escritura no autorizada: TDATAROW:codigo
Args:
[ 1] = O TDATAROW
Pero un registro nuevo igualmente puede tener un código libre, eso lo permite MySql.
Espero haber sido claro.
English:
But a new record can still have a free code, that is allowed by MySql. I hope I was clear.
El GetAutoIncrement(cTable) lo reemplace por una funcion propia simple:
- Code: Select all Expand view RUN
FUNCTION GetAutoIncrement(cTable,cField)
RETURN oApp:oServer:QueryResult('SELECT MAX('+cField+') FROM ' + cTable) + 1
ID FLD1 FLD2
1 AA AAAA
2 BB BBBB
INSERT INTO table (ID,FLD1,FLD2) VALUES ( 3, 'CC','CCCC' )
INSERT INTO table (ID,FLD1,FLD2) VALUES ( 3, 'DD','DDDD' )
TRY
oCn:BeginTransaction()
oQry:Save()
oCn:CommitTransaction()
CATCH oError
MsgStop("Error al grabar"+CHR(10)+oError:description,"Error")
oCn:RollBack()
END TRY
cmsoft wrote:Igualmente, siguiendo su ejemplo, el error se puede capturar con un TRY CATCH e indicárselo al usuario:
- Code: Select all Expand view RUN
TRY
oCn:BeginTransaction()
oQry:Save()
oCn:CommitTransaction()
CATCH oError
MsgStop("Error al grabar"+CHR(10)+oError:description,"Error")
oCn:RollBack()
END TRY
Esto está bien?
if oRs:Save()
// Success
// appropriate code
else
// failure
oCn:ShowError() // optional
// suitable action on failure
endif
oCn:lShowErrors := .t.
if oRs:Save()
// success
else
// failure. Automatic error message
endif
oCn:lShowErrors := .t. // can be a global setting
oCn:BeginTransaction()
if oRs1:Save() .and. oRs2:Save() .and. ;
oRs3:Save() .and. oRs4:Save()
oCn:CommitTransaction()
else
oCn:RollBack()
endif
TRY
oCn:BeginTransaction()
oCn:Execute(cSql1)
oCn:Execute(cSql2)
oCn:Execute(cSql3)
oCn:CommitTransaction()
CATCH oError
MsgStop("Error al grabar"+CHR(10)+oError:description,"Error")
oCn:RollBack()
END TRY
oCn:lShowErrors := .t. // can be a global setting
oCn:BeginTransaction()
if oCn:Execute(cSql1) .and. oCn:Execute(cSql2) .and. ;
oCn:Execute(cSql3)
oCn:CommitTransaction()
else
oCn:RollBack()
endif
oCn:lShowErrors := .t. // global setting
oCn:BeginTransaction()
lSuccess := .t.
for each cSql in { cSql1, cSql2, ... cSqlN }
oCn:Execute( cSql )
if oCn:nError != 0
lSucess := .f.
EXIT
endif
next
if lSuccess
oCn:CommitTransaction()
else
oCn:RollBack()
endif
oCn:lShowErrors := .t. // global setting
TRY
oCn:BeginTransaction()
for each cSql in { cSql1, cSql2, ... cSqlN }
oCn:Execute( cSql )
if oCn:nError != 0
THROW()
endif
next
oCn:CommitTransaction()
CATCH
oCn:RollBack()
END
oCn:lShowErrors := .t. // global setting
oCn:lThrowError := .t. // local setting
TRY
oCn:BeginTransaction()
for each cSql in { cSql1, cSql2, ... cSqlN }
oCn:Execute( cSql )
next
oCn:CommitTransaction()
CATCH
oCn:RollBack()
END
oCn:lThrowError := .f.
oCn:lThrowError := .t.
YOUR PRESENT TRY/CATCH CODE
oCn:lThrowError := .f.
// parent and 2 childs
#include "fivewin.ch"
function Main()
local oCn, o
local oRsState, oRsCity, oRsCust
local oBrwState, oBrwCity, oBrwCust
local oDlg, oFont
oCn := FW_DemoDB()
//oCn:lShowErrors := .t.
MsgRun( "Reading tables", "Please Wait...", ;
<||
oCn:lThrowError := .t.
try
oRsState := oCn:RowSet( "SELECT * FROM states ORDER BY name" )
oRsCity := oCn:RowSet( "SELECT id, state, city FROM customer ORDER BY state, city" ) //es customers
oRsCust := oCn:RowSet( "SELECT id, state, CONCAT_WS( ', ', first, last ) AS Name FROM customers ORDER by state,Name" )
catch o
?o:Description
return nil
end
oCn:lThrowError := .f.
oRsCity:SetFilter( "STATE = ?", { oRsState:code } )
oRsCust:SetFilter( "STATE = ?", { oRsState:code } )
return nil
> )
DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-10 PTS
DEFINE DIALOG oDlg SIZE 700,600 PIXEL TRUEPIXEL FONT oFont ;
TITLE "MARIADB - PARENT WITH TWO CHILD TABLES"
RELEASE FONT oFont
@ 20,20 XBROWSE oBrwState SIZE 300,-20 PIXEL OF oDlg DATASOURCE oRsState ;
COLUMNS "NAME","CODE" CELL LINES NOBORDER
WITH OBJECT oBrwState
:SetGroupHeader( "PARENT", 1, 2 )
:nStretchCol := 1
:lHScroll := .f.
:bChange := <||
oRsCity:ReFilter( { oRsState:code } )
oRsCust:ReFilter( { oRsState:code } )
oBrwCity:Refresh()
oBrwCust:Refresh()
return nil
>
:CreateFromCode()
END
@ 20,300 XBROWSE oBrwCity SIZE 400,260 PIXEL OF oDlg DATASOURCE oRsCity ;
COLUMNS "STATE","CITY" CELL LINES NOBORDER
WITH OBJECT oBrwCity
:SetGroupHeader( "CHILD-1", 1, 2 )
:nStretchCol := 2
:lHScroll := .f.
:CreateFromCode()
END
@ 280,300 XBROWSE oBrwCust SIZE 400,-20 PIXEL OF oDlg DATASOURCE oRsCust ;
COLUMNS "STATE","NAME" CELL LINES NOBORDER
WITH OBJECT oBrwCust
:SetGroupHeader( "CHILD-2", 1, 2 )
:nStretchCol := 2
:lHScroll := .f.
:CreateFromCode()
END
ACTIVATE DIALOG oDlg CENTERED
oCn:Close()
return nil
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 95 guests