Author: Bhavbhuti Nathwani
Posted: 2004-01-08 02:55:42 Link
Hi all
Where is the best place to put in the command
replace iid with CBNewID("tablename")
I have considered bo.beforenew()
Any place that is more righter than this. Please note I will be using
this in the parent_bo as well as the child_bo same place. Hope this
does not disturb the auto populating of the child FK.
Please advise.
Author: Ed Leafe
Posted: 2004-01-08 07:18:56 Link
Quote: >>Where is the best place to put in the command
replace iid with CBNewID("tablename")
I have considered bo.beforenew()
Any place that is more righter than this. Please note I will be using
this in the parent_bo as well as the child_bo same place. Hope this
does not disturb the auto populating of the child FK.
This is already done for you in the OnNew() method, if you have that
set as the default value for the iID field. BeforeNew() wouldn't work,
since the new record isn't created yet - you would be changing the ID
of the current record there. AfterNew() could also work, but that is
fired after SetMemento(), so that changing the ID there would mark the
record as modified, requiring the "Do you want to save your changes?"
message box if the user immediately cancels the Add.
Author: Bhavbhuti Nathwani
Posted: 2004-01-08 08:18:19 Link
Quote: >>This is already done for you in the OnNew() method, if you
have that set as the default value for the iID field. BeforeNew()
wouldn't work, since the new record isn't created yet - you would be
changing the ID of the current record there. AfterNew() could also
work, but that is fired after SetMemento(), so that changing the ID
there would mark the record as modified, requiring the "Do you want to
save your changes?" message box if the user immediately cancels the
Add.
Actually this is the code I have still under construction:
<code>
LOCAL llRetVal, loLastRecord, lnConHnd, liID, lnNextId
llRetVal = DODEFAULT()
lnConnHnd =
SQLSTRINGCONNECT("DSN=C99_VSO3Data_FireBird;DRIVER=OdbcJdbc;DBNAME=D:\Shared\C99\Data\VSO3.FDB;UID=SYSDBA;PWD=masterkey")
= SQLEXEC(lnConnHnd , [SELECT
gen_id(GEN_MSALESREPS_ID,1) AS lnNextId from
rdb$VSO3])
liID = lnNextId
wait window str(liID) + str(lnNextId)
RETURN llRetVal
</code>
So in essence I am replacing the default for the view, is end of
beforenew() good enough. I have called the dodefault() and studying
the inherited code I assumed that the record is append blank somewhere
down the line, thus my decision.
Please advise. I want the functionality of default CBNewID() but
programatically.
Thanks.
Author: Ed Leafe
Posted: 2004-01-08 08:36:16 Link
Quote: >>Actually this is the code I have still under construction:
<code>
LOCAL llRetVal, loLastRecord, lnConHnd, liID, lnNextId
llRetVal = DODEFAULT()
lnConnHnd =
SQLSTRINGCONNECT("DSN=C99_VSO3Data_FireBird;DRIVER=OdbcJdbc;DBNAME=D:\Shared\C99\Data\VSO3.FDB;UID=SYSDBA;PWD=masterkey")
= SQLEXEC(lnConnHnd , [SELECT
gen_id(GEN_MSALESREPS_ID,1) AS lnNextId from
rdb$VSO3])
liID = lnNextId
wait window str(liID) + str(lnNextId)
RETURN llRetVal</code>
So in essence I am replacing the default for the view, is end of
beforenew() good enough. I have called the dodefault() and studying
the inherited code I assumed that the record is append blank somewhere
down the line, thus my decision.
Oh, so you're using remote data. Normally the remote database has its
own method of key generation, such as autoincrement fields in MySQL.
In those cases, you don't generate the ID locally; you simply commit
the new record without a value in the ID field, and then call the
database server function that returns the ID of the last record that
was inserted. You can then replace the iID field of the local record
with that value.
I see from your DSN that you are using Firebird as your database. I
don't have any experience with that product, so I'll leave it to
others to fill in the specifics as to how to best do this with
Firebird.
Author: Bhavbhuti Nathwani
Posted: 2004-01-08 09:28:58 Link
Quote: >>Oh, so you're using remote data. Normally the remote database
has its own method of key generation, such as autoincrement fields in
MySQL. In those cases, you don't generate the ID locally; you simply
commit the new record without a value in the ID field, and then call
the database server function that returns the ID of the last record
that was inserted. You can then replace the iID field of the local
record with that value.
I see from your DSN that you are using Firebird as your database. I
don't have any experience with that product, so I'll leave it to
others to fill in the specifics as to how to best do this with
Firebird.
Yes Firebird has a key generator but has to be called manually as I
did above, though the assignment statement before the wait window line
still is unpopulated so I am working on it. But it seems that we have
to get the next key just like we do in VFP <g>.
Also MySQL if used with a non-open-source product is not free to use.
Am I correct in understanding?
Author: Ed Leafe
Posted: 2004-01-08 09:39:09 Link
Quote: >>Also MySQL if used with a non-open-source product is not free
to use. Am I correct in understanding?
Depends. If you distribute MySQL with your app, then yes, you must
license it. But if you do not distribute the app (i.e., such as
in-house applications), then no, you do not.
Author: Bhavbhuti Nathwani
Posted: 2004-01-09 00:43:21 Link
Quote: >>Depends. If you distribute MySQL with your app, then yes, you
must license it.
I wont have so much in-house work and will like to make commercial
apps, so I guess I will not invest anything but curiosity in MySQL
<g>.
Author: Bhavbhuti Nathwani
Posted: 2004-01-09 03:03:56 Link
Quote: >>Oh, so you're using remote data. Normally the remote database
has its own method of key generation, such as autoincrement fields in
MySQL. In those cases, you don't generate the ID locally; you simply
commit the new record without a value in the ID field, and then call
the database server function that returns the ID of the last record
that was inserted. You can then replace the iID field of the local
record with that value.
I see from your DSN that you are using Firebird as your database. I
don't have any experience with that product, so I'll leave it to
others to fill in the specifics as to how to best do this with
Firebird.
Eureka, I just found out a fine place to put in such code:
iDataBhaviour.GetNextRemotePK()
<code>LPARAMETERS tcBaseTable
LOCAL lnConHnd, lnOldArea, luRetVal
*** we are overriding the parent logic
lnOldArea = SELECT(0)
lnConnHnd = CURSORGETPROP("ConnectHandle")
= SQLEXEC(lnConnHnd , [SELECT gen_id(GEN_] +
STRTRAN(tcBaseTable, "DBO.", "") +
[_ID, 1) AS nNextId from rdb$database])
luRetVal = VAL(sqlResult.nNextID)
SELECT (lnOldArea)
RETURN luRetVal</code>
Now the problem. If I have overridden i class, that means my personal
framework is now either VFP or FireBird for remote data.
How can I make it application wise, this time if not VFP FireBird,
next time if not VFP MySQL?
I wouldn't have known about this function if it had not created an
error by the default c-level code.
I like to code in VFP8 and the app will eventually move to it, but for now, I have to compile in VFP6.
However, this #IF doesn't seem to work. Why not? Or better yet, is there an easier way to do this so that I can still have the code exist for inclusion when compiled later in VFP8?
Here's my code:
#IF val(left(VERSION(4),2)) > 6
llValid = .F.
DO WHILE !llValid AND !EMPTY(lcEmailAddr)
lcEmailAddr = INPUTBOX("The Report will be emailed to the address below. You can use this one, or type in a different address to use.","Email address for Report.",pcEmailAddr)
llValid = this.ValidEmail(lcEmailAddr) OR EMPTY(lcEmailAddr) && allow user to get out via empty email address
IF !llValid THEN
MESSAGEBOX("The email address should be in the form yourname@yourcompany.com' -- please correct and resubmit.",MB_ICONOK,"Invalid email address.")
ENDIF
ENDDO
#ENDIF
TIA!
--Michael
in vfp7 (in the command window):
#if val(left(VERSION(4),2)) > 6
?'run' && run
#endif
#if val(left(VERSION(4),2)) > 7
?'run' &&
#endif
AndyD 8-)#