Skip to content

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

Open
@Samba143

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions