FW MariaDB/MySql native

FW MariaDB/MySql native

Postby Mike Serra » Wed Dec 30, 2020 9:36 am

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  Expand view

oRs:=oConnection:Rowset("select * from operators")
....
oRs:Add()
 


2) I manipulate the fields
Code: Select all  Expand view

oRs:Codigo:=  ¿¿¿¿¿
oRs:Nombre:=  ?????
 


3) Finally, I save the record.
Code: Select all  Expand view

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: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: FW MariaDB/MySql native

Postby Mike Serra » Sat Jan 02, 2021 6:49 am

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

Re: FW MariaDB/MySql native

Postby nageswaragunupudi » Sat Jan 02, 2021 9:37 am

Please wait.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10313
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: FW MariaDB/MySql native

Postby Maurizio » Sat Jan 02, 2021 11:56 am

maybe it's the same problem ?

viewtopic.php?f=3&t=34272&p=203181&hilit=Mysql#p203181

Maurizio
User avatar
Maurizio
 
Posts: 799
Joined: Mon Oct 10, 2005 1:29 pm

Re: FW MariaDB/MySql native

Postby Mike Serra » Mon Jan 11, 2021 8:32 am

Good morning.

Any news?

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

Re: FW MariaDB/MySql native

Postby Mike Serra » Fri Jan 22, 2021 3:27 pm

Good afternoon.

any news?

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

Re: FW MariaDB/MySql native

Postby James Bott » Fri Jan 22, 2021 5:29 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: FW MariaDB/MySql native

Postby Mike Serra » Mon Jan 25, 2021 8:56 am

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.
Mike Serra
 
Posts: 297
Joined: Fri Apr 14, 2006 5:52 pm
Location: Córdoba (España)

Re: FW MariaDB/MySql native

Postby James Bott » Mon Jan 25, 2021 2:33 pm

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
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 42 guests

cron