Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of Auto Increment Columns with Recordset::AddNew() #18

Open
Samba143 opened this issue Sep 20, 2024 · 0 comments
Open

Handling of Auto Increment Columns with Recordset::AddNew() #18

Samba143 opened this issue Sep 20, 2024 · 0 comments

Comments

@Samba143
Copy link

I have a table with Primary Key on a column named ID.

CREATE TABLE [MyTest](
[ID] [integer] PRIMARY key,
[Subject] VARCHAR NOT NULL,
[Marks] [integer] NOT NULL DEFAULT 0);

I am using a class derived from CRecordset by implementing DoFieldExchange for all the 3 columns with field type as OutputColumn.
Below is code snippet used to insert new record.

MyTest rs(pdb);
try
{
rs.Open();
rs.AddNew();

	rs.m_Subject = _T("Maths");
	rs.m_Marks = 10;

	rs.Update();
	rs.Close();
}

The inserted row has unexpected / undesired value for ID column.
Although the recordset field member is not initialized explicitly, the record set buffer created by AddNew() operation has the max value of the int32 which gets inserted into table.

I would like the database to resolve and generate value for ID column.
How can I achieve the desired output with this ODBC driver?

for quick reference , I tried this scenario with MS Access database using Access driver and it woks as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant