FW MariaDB/MySql native

Post Reply
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

FW MariaDB/MySql native

Post by Mike Serra »

Hi to all Forum:

First of all I congratulate you on the holidays and wish you a good exit to the year of 2020 (screwed) and a better entry into 2021.

I would need help for the following: I have started to make examples of a CRUD of a table with the native functions of FWH (Ver. 16.10), and the code is similar to what I show:

1) I open the recordset and add a blank record

Code: Select all

oRs:=oConnection:Rowset("select * from operators")
....
oRs:Add()
 
2) I manipulate the fields

Code: Select all

oRs:Codigo:=  ¿¿¿¿¿
oRs:Nombre:=  ?????
 
3) Finally, I save the record.

Code: Select all

oRs:Save()
 
If the server does not give any errors, it works perfectly. The problem is that the table I am manipulating has a UNIQUE index in the "Codigo" field, so if I try to create a record with an existing code, it gives me an error, but the problem is that it is as if the pointer moved and gets lose their values ​​(they go blank). Do you know or do you have any example to be able to carry out this basic process?

Best regards, and thank you very much.
Last edited by Mike Serra on Sat Jan 02, 2021 6:47 am, edited 1 time in total.
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: FW MariaDB/MySql native

Post by Mike Serra »

:roll:
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: FW MariaDB/MySql native

Post by nageswaragunupudi »

Please wait.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Maurizio
Posts: 705
Joined: Mon Oct 10, 2005 1:29 pm
Contact:

Re: FW MariaDB/MySql native

Post by Maurizio »

maybe it's the same problem ?

https://forums.fivetechsupport.com/view ... ql#p203181

Maurizio
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: FW MariaDB/MySql native

Post by Mike Serra »

Good morning.

Any news?

Thanks in advance
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: FW MariaDB/MySql native

Post by Mike Serra »

Good afternoon.

any news?

Thanks in advance
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FW MariaDB/MySql native

Post by James Bott »

Most databases automatically create the primary key when a new record is added. Thus they won't allow you to update the primary key.

DBFs are the exception to this, however there is now the option to specify an automatic primary key for DBFs too.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Mike Serra
Posts: 287
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: FW MariaDB/MySql native

Post by Mike Serra »

Hello James:

Thanks for your comment. Actually, the problem I have is when trying to add a record and the server returns an error (in my case, because the code already exists). In this case, the values ​​of the oRs variable are lost. The code field has created a unique index on the server.

I could carry out this check, but I prefer to control it more securely at the database level, because the application can be accessed from desktop software and web applications.

Thanks.
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: FW MariaDB/MySql native

Post by James Bott »

Mike,

I guess I wasn't clear, all you have to do is use automatic primary keys with DBFs. You do this by using the field type "+" for the primary key field. Then when you add a blank record it will automatically get a primary key ID. This way you can use the same code for both DBFs and SQL databases.

Or, maybe still I don't understand your problem?
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Post Reply