bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

SQL Server Identity Insert #1193

Closed NoToComments closed 4 years ago

NoToComments commented 4 years ago

Hello I cant get fatfree working with sqlserver.

On Inserts it sends 0 as id to sqlserver. Instead of leaving the column out of the insert statement.

CREATE TABLE [dbo].[example](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [name] [varchar](50) NOT NULL
) ON [PRIMARY]
GO

Current behavior

INSERT INTO [dbo].[example]
           (id,[name])
     VALUES
           (0,'test')

Wished behavior

INSERT INTO [dbo].[example]
           ([name])
     VALUES
           (<name, varchar(50),>)

Looks like https://github.com/bcosca/fatfree/issues/1192

xfra35 commented 4 years ago

I guess you're talking about the SQL mapper right? Can you provide a code sample?

NoToComments commented 4 years ago

Yeah its about the mapper.

Something like that?

$database = new \DB\SQL(
            'sqlsrv:server=localhost,1433;database=testDB',
            'sa',
            'P@ssw0rd'
        );

        $example=new \DB\SQL\Mapper($database,'example');
        $example->name="SpaceOps";
        $example->save();

Error code

PDOStatement: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Cannot insert the value NULL into column 'id', table 'shortyTest.dbo.project'; column does not allow nulls. INSERT fails.

ikkez commented 4 years ago

Can you please check latest commit https://github.com/bcosca/fatfree-core/commit/95d5f68aa4b8a7c23b3493bfdb8c02f275e4c0ec at master branch. I've just tested it with SQL Server 2017 myself now and it all works fine here.

ikkez commented 4 years ago

please reopen if problem persists.