SET LANGUAGE us_english;  -- avoid month day swap in datetime

GO

GO

GO

GO

GO

GO

GO

GO

GO

GO

GO

GO

GO

GO

DROP SCHEMA qgis_test;
GO

CREATE SCHEMA qgis_test;
GO

CREATE TABLE qgis_test.[someData] (
    pk integer PRIMARY KEY,
    cnt integer,
    name nvarchar(max) DEFAULT 'qgis',
    name2 nvarchar(max) DEFAULT 'qgis',
    num_char nvarchar(max),
    dt datetime,
    [date] date,
    [time] time,
    geom geometry
);
GO

CREATE TABLE qgis_test.[some_poly_data] (
    pk integer PRIMARY KEY,
    geom geometry
);
GO

CREATE TABLE qgis_test.[date_times] (
       id integer PRIMARY KEY,
       date_field date,
       time_field time,
       datetime_field datetime
);
GO

CREATE TABLE qgis_test.[float_dec] (
       id integer PRIMARY KEY,
       float_field float,
       dec_field decimal(7,3)
);
GO

CREATE TABLE qgis_test.[multiGeomColumns] (
    pk integer PRIMARY KEY,
    geom1 geometry,
    geom2 geometry
);
GO

CREATE TABLE qgis_test.[sacrificialLamb] (
    pk integer PRIMARY KEY
);
GO

INSERT INTO qgis_test.[someData] (pk, cnt, name, name2, num_char, dt, [date], [time], geom) VALUES
(5, -200, NULL, 'NuLl', '5', '2020-05-04 12:13:14', '2020-05-02', '12:13:01', geometry::STGeomFromText( 'Point(-71.123 78.23)', 4326 )),
(3,  300, 'Pear', 'PEaR', '3', NULL, NULL, NULL, NULL),
(1,  100, 'Orange', 'oranGe', '1', '2020-05-03 12:13:14', '2020-05-03', '12:13:14', geometry::STGeomFromText( 'Point(-70.332 66.33)', 4326 )),
(2,  200, 'Apple', 'Apple', '2', '2020-05-04 12:14:14', '2020-05-04', '12:14:14', geometry::STGeomFromText( 'Point(-68.2 70.8)', 4326 )),
(4,  400, 'Honey', 'Honey', '4', '2021-05-04 13:13:14', '2021-05-04', '13:13:14', geometry::STGeomFromText( 'Point(-65.32 78.3)', 4326 ))
;
GO

INSERT INTO qgis_test.[some_poly_data] (pk, geom) VALUES
(1, geometry::STGeomFromText('Polygon ((-69.0 81.4, -69.0 80.2, -73.7 80.2, -73.7 76.3, -74.9 76.3, -74.9 81.4, -69.0 81.4))', 4326 )),
(2, geometry::STGeomFromText('Polygon ((-67.6 81.2, -66.3 81.2, -66.3 76.9, -67.6 76.9, -67.6 81.2))', 4326 )),
(3, geometry::STGeomFromText('Polygon ((-68.4 75.8, -67.5 72.6, -68.6 73.7, -70.2 72.9, -68.4 75.8))', 4326 )),
(4, NULL)
;
GO

INSERT INTO qgis_test.[date_times] (id, date_field, time_field, datetime_field ) VALUES
 (1, '2004-03-04', '13:41:52', '2004-03-04 13:41:52' );

INSERT INTO qgis_test.[float_dec] (id, float_field, dec_field ) VALUES
 (1, 1.1111111111, 1.123 );
GO

INSERT INTO qgis_test.[sacrificialLamb] (pk) VALUES
 (1);
GO

INSERT INTO qgis_test.[multiGeomColumns] (pk, geom1, geom2) VALUES
(5, geometry::STGeomFromText( 'Point( 1 2 )', 4326 ), NULL),
(3, NULL, geometry::STGeomFromText( 'LineString( 1 2, 3 4 )', 4326 )),
(1, geometry::STGeomFromText( 'Point( 2 3 )', 4326 ), geometry::STGeomFromText( 'LineString( 2 3, 4 5 )', 4326 )),
(2, geometry::STGeomFromText( 'Point( 3 4 )', 4326 ), geometry::STGeomFromText( 'LineString( 3 4, 5 6 )', 4326 )),
(4, geometry::STGeomFromText( 'Point( 5 6 )', 4326 ), geometry::STGeomFromText( 'LineString( 5 6, 7 8 )', 4326 ))
;
GO

/** Contains invalid polygons **/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [qgis_test].[invalid_polys](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[ogr_geometry] [geometry] NULL,
 CONSTRAINT [PK_invalid_parcels] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
SET IDENTITY_INSERT [qgis_test].[invalid_polys] ON 

GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (258348, 0x47100000010408000000DC293B02AABE654008C8480AADC144C05C395D11AABE6540D81F66D1A9C144C0CC35D9FAAABE654050DD9A16AAC144C0ECCDD77BADBE6540506342CCA5C144C0E04E1598ADBE65402071DEEBA3C144C0B4DF72A6ADBE6540C8D4A2ADA6C144C088403273AABE6540982A29C1ACC144C0DC293B02AABE654008C8480AADC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (1528836, 0x4710000001001000000074C8AF1AB9BE6540581FB97CFEC044C0381C2E23B9BE6540C8788F91FEC044C0582BE746B9BE654030831B3DFFC044C0281F717EB9BE6540A0DFEBFCFFC044C058C8128CB9BE6540686A1E2F00C144C034FF507FB9BE6540D881240000C144C004DAC298B9BE6540484FCF5D00C144C0846AC076B9BE654010E836F502C144C05CB8077CB9BE654008FA501103C144C0D07A3596B9BE6540F8FDA78A05C144C00CB48933B9BE6540F8555E9706C144C08C6D52D1B8BE65407010F7A207C144C0B0DE03CFB8BE654048AD41A907C144C0A0C97789B7BE654090F0A0200BC144C06845E570B7BE654000DD860703C144C074C8AF1AB9BE6540581FB97CFEC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (1528864, 0x47100000010016000000DCFADC15B9BE6540D0386351FEC044C0F4C5FCE1B9BE65406083B93BFDC044C0DCBD37E1B9BE654010BBAA44FDC044C0B80970DAB9BE654098B5BE8FFDC044C048AD4ED3B9BE654030D28BDAFDC044C0F4A0F7CBB9BE6540F06C3425FEC044C0184CB2C4B9BE654088890170FEC044C0C44D57C1B9BE65405016AD92FEC044C048C950BAB9BE6540008F9CDDFEC044C0C8444AB3B9BE654098AB6928FFC044C03C985EACB9BE654020A67D73FFC044C00CBCB1A5B9BE6540A8A091BEFFC044C03C474C9FB9BE65402079EC0900C144C0B4E96399B9BE65405055905500C144C004DAC298B9BE6540484FCF5D00C144C034FF507FB9BE6540D881240000C144C058C8128CB9BE6540686A1E2F00C144C0281F717EB9BE6540A0DFEBFCFFC044C0582BE746B9BE654030831B3DFFC044C0381C2E23B9BE6540C8788F91FEC044C074C8AF1AB9BE6540581FB97CFEC044C0DCFADC15B9BE6540D0386351FEC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705263, 0x47100000010405000000988FB5D0DFBE6540284A2C3D9BC044C01CA53ED5E0BE654088FFC34999C044C05CEBA9DAE0BE6540C0D2596399C044C06C4C20D6DFBE6540889B9D569BC044C0988FB5D0DFBE6540284A2C3D9BC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705291, 0x4710000001040F000000548E7F55E4BE6540A829FDE264C144C020EEEA55E4BE654028F86D8871C144C070CF4E61E0BE65409052B34E6FC144C00037E6D0DDBE654010EECEDA6DC144C058433DD8DDBE6540588467E461C144C0FCF0EFDDDDBE654030241BA058C144C0309882DFDDBE6540A878C83956C144C0F458F6CEDFBE6540C8D7603F56C144C0A8B79AD0DFBE654070DC1DAA4DC144C0F82C3767E0BE654090203F624EC144C0180D0C65E0BE654058CC74545AC144C058868263E0BE65401045E86A62C144C07461495EE2BE65402873F84662C144C0EC955B55E4BE6540D8475D2162C144C0548E7F55E4BE6540A829FDE264C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705302, 0x4710000001040900000010EDCBE8A3BE6540805302A927C144C0580016A3A5BE6540901E865627C144C0B4D187CEA5BE6540C0887D0228C144C0C89F9B42A6BE654068C5E8CD29C144C080E158C1A6BE654040C967C32BC144C01CEA0F7EA6BE6540C0E44B4A2FC144C004B6EFF6A5BE654048B19EB82EC144C0FCDDFE06A4BE65401878556A2DC144C010EDCBE8A3BE6540805302A927C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705306, 0x47100000010448000000205727BDD8BE6540282FE3BA2AC144C078126CB7D8BE6540906E3AB82AC144C0C4D6C79ED8BE654028322EAD2AC144C004733E86D8BE6540487ABDA02AC144C0B472D476D8BE654018DF17972AC144C0C8969B5ED8BE6540D805C1852AC144C048B38646D8BE654088F12E722AC144C0C03E952ED8BE6540D8BD5A5D2AC144C0E0BF5B1BD8BE654088C31C4E2AC144C0D4FC4F03D8BE6540684F1F3A2AC144C0C83F70EBD7BE6540183ABB242AC144C010BCC6D3D7BE6540E8A1600D2AC144C0385776BCD7BE6540E06E5FF329C144C00010CEACD7BE654068DCF1DF29C144C0D8BA1E96D7BE6540D8092FC129C144C09415A57FD7BE6540F839E3A029C144C03CB13D69D7BE6540582CE57F29C144C0B0B33F55D7BE65408898A66329C144C06C0EC63ED7BE6540804A7F4329C144C014AA5E28D7BE6540E876EA2229C144C040941112D7BE65408009810129C144C018BD5301D7BE65405058A4E728C144C09C7745EBD6BE6540B049D4C428C144C0107349D5D6BE65406037BBA128C144C00C4E44BFD6BE6540D04AA47E28C144C084E25FB5D6BE65408050666F28C144C0884E379FD6BE65408023264D28C144C090511789D6BE654080F6E52A28C144C0A0EBFF72D6BE6540D0C55C0828C144C0B49DC370D6BE654070A5480528C144C02450F059D6BE6540583568E527C144C03C7BB543D6BE6540388A4CC327C144C084B6042FD6BE6540989ABF9A27C144C0E8DA3526D6BE6540B0C5848427C144C0B8BAA014D6BE6540F843894F27C144C074931804D6BE654040C0E91627C144C078D210F5D5BE6540409522E526C144C08453E2E4D5BE6540B0B117AC26C144C0282B93D5D5BE65401071187126C144C00C5DD7CFD5BE654090DC065A26C144C018E5A6C1D5BE654048B9A51C26C144C0CCEB3AB4D5BE6540983C99DD25C144C03C2A55A7D5BE6540A0FC6C9D25C144C08887C89AD5BE654000DBB05C25C144C040A35693D5BE6540A08D5C3725C144C0FC89CA86D5BE6540006CA0F624C144C0A4B77C7AD5BE6540706C9DB524C144C0B0464A6ED5BE6540F08E537424C144C040243262D5BE6540982FE53224C144C08CC58D60D5BE6540B891C82A24C144C028136053D5BE654098D3C0EA23C144C0BC322146D5BE65409071DBAA23C144C0B4503239D5BE6540A853686A23C144C0D49EED2CD5BE654040D2402923C144C06C5CB521D5BE654060D5B4E622C144C0E4F0D017D5BE654058597BA222C144C02C4A2717D5BE6540005A4E9D22C144C04815020FD5BE654000FFFB5622C144C0BC681608D5BE654018FFF90E22C144C0C47B0102D5BE6540606523C621C144C08CC672FCD4BE6540D86BE17C21C144C0E039B2F7D4BE6540201E8E5021C144C090C463F0D4BE654078A6700721C144C02C9725EBD4BE654030872CBE20C144C0E8C7ADE9D4BE6540E02D7F7420C144C0F8F690EBD4BE6540A863F54420C144C0140D52F0D4BE6540682C01FB1FC144C0B8C6495CD5BE654070ABD6781FC144C0880AE2F7D7BE6540B05CCA541CC144C07C14BF73D9BE654078A1BE071DC144C0A0DF41FDD8BE6540A073B7EB25C144C0205727BDD8BE6540282FE3BA2AC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705315, 0x47100000010419000000487D59DA89BE654040E9B520EEC044C0281CA90D8ABE6540A8BC5642F7C044C038ACA92C8ABE6540F805AFEEFCC044C0F0AB353E8ABE654018A358B5FEC044C08CC80B448ABE6540C879104CFFC044C03CF6B3588ABE6540804EAD6301C144C0D87EB9B68ABE6540308C43E90AC144C0587FA2B78ABE6540C864C7FF0AC144C088231C6E88BE654060AED46C0BC144C0940FF34588BE654068E960B60AC144C0C056091687BE654050EBDBEE0AC144C000FCDA9A87BE654038573E1209C144C07472497F86BE6540C8A194FC07C144C0E45F22E383BE6540B0E5DF7808C144C0B0F089D083BE6540803E208904C144C080E9B46E83BE6540A0D2329904C144C050060A6683BE65403854F8D802C144C0CCFE226383BE654070211E4202C144C010B0935083BE6540B01FB883FEC044C0B436323483BE654000BB3ACAF8C044C054BFDF2383BE6540B0D705CDF8C044C088A574F582BE6540D848D469EFC044C03CBA1E4087BE6540282D019DEEC044C0B4A84F7287BE6540D0138093EEC044C0487D59DA89BE654040E9B520EEC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705332, 0x47100000010406000000E8F5CC37A7BE654030325C78B9C044C05C36EC57A7BE654058863D8FBFC044C0E81432F7A3BE6540F8354D30C0C044C0E85D13D7A3BE6540D0E16B19BAC044C0DC006C40A4BE654080CDD905BAC044C0E8F5CC37A7BE654030325C78B9C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705349, 0x47100000010410000000789F99168BBE6540E02BBAF59AC044C0601BB4018FBE6540B06763809FC044C0C489F9038FBE654000F0F4EF9FC044C064D2D2218FBE6540581FF997A5C044C07C4706198EBE6540F0422EC9A5C044C0682515DC8BBE654078510034A6C044C05833897F8ABE654000E13ED09CC044C03877E7958ABE6540A0AD3EAF9CC044C00CD539AB8ABE6540C8E485889CC044C08CAA52BF8ABE6540E818575C9CC044C028120FD28ABE65407873FD2A9CC044C098004AE38ABE6540782EE2F49BC044C0C819E1F28ABE6540B8A970BA9BC044C06852AF008BBE6540C06A167C9BC044C0707CA30C8BBE6540B0075F3A9BC044C0789F99168BBE6540E02BBAF59AC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705382, 0x471000000104080000004076830DB4BE654028525040C9C044C064CB8A92B4BE6540780069A4CAC044C0984121A7B4BE6540A84A0C16CFC044C034C5DFA0B4BE6540086A4E17CFC044C00C36BFABAFBE654018D0FF03D0C044C0A4D57F8CAFBE6540F0C45617CAC044C0008569CEB0BE6540F06415DBC9C044C04076830DB4BE654028525040C9C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705449, 0x47100000010407000000E860C03CBBBE6540C037A39F96C044C0BC794F8ABBBE6540E8515D6592C044C00428EFDEBFBE654028AB443495C044C0340F6091BFBE654060AFFA6D99C044C09CC76130BFBE654030D2D0AE9EC044C0344408D4BABE6540B05CCA549CC044C0E860C03CBBBE6540C037A39F96C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705451, 0x4710000001040C000000387DD57BAEBE6540C82479675AC044C03CD7EAB7AEBE654080DCD4F95DC044C08CF85BF6ACBE6540A09740005FC044C07477AA37ABBE654098D3FE0460C044C074DB2A2DA8BE6540A0026CAF61C044C0E0B3380DA8BE6540E053568C60C044C0503B57EFABBE65405802846A5EC044C0CC683283ABBE6540787BC67457C044C07457CD78ADBE6540F8FA98B156C044C0B45BAD0EAEBE6540E879707756C044C0A8F4C53EAEBE654050A3906456C044C0387DD57BAEBE6540C82479675AC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705469, 0x4710000001040A000000D4940964DBBE654010B3DC4148C144C0D0CB2896DBBE654098B03B7F48C144C010B9B18ADBBE654078CCF6D761C144C000C8EBBCDBBE6540108CCDD861C144C058433DD8DDBE6540588467E461C144C00037E6D0DDBE654010EECEDA6DC144C094048A53DBBE654038FDEABB6CC144C020AA7758DBBE6540E80C20D761C144C07832B159DBBE654020435B295FC144C0D4940964DBBE654010B3DC4148C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705540, 0x4710000001041700000008453064DEBE6540704057CA0EC144C0608216BCDFBE6540A8AF3D6C0FC144C05CEF2AB0DFBE6540E8DC864E18C144C00461C5AEDFBE6540403CF58F18C144C0BC8A4FABDFBE6540D85DB1D018C144C0008DD2A5DFBE654040DE061019C144C0B8A8609EDFBE654078DFAE4D19C144C0E8740295DFBE6540F8A1D28819C144C0F852D389DFBE6540F0C506C119C144C0F470E47CDFBE654090EBDFF519C144C02471636EDFBE654020D5AB261AC144C0A4186A5EDFBE654008DB43531AC144C0D0C8134DDFBE6540100BFA7A1AC144C000BB963ADFBE6540D897A59D1AC144C0B8D41527DFBE65405847DDBA1AC144C0E8C5C612DFBE654078BD7ED21AC144C05879C5FDDEBE6540A8741CE41AC144C08C4358E8DEBE6540F86CB6EF1AC144C0EC859AD2DEBE6540404A2AF51AC144C04431D4BCDEBE6540800C78F41AC144C090B428A7DEBE6540E8317BED1AC144C0FC62F3C7DDBE654060247B841AC144C008453064DEBE6540704057CA0EC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705563, 0x47100000010407000000B412A91FAABE6540F094698FF2C044C020F4119DAABE6540A8A1BE79F2C044C0FC874F95AABE6540F099CF00F1C044C068A96164AEBE6540C0317C58F0C044C06C95421BAEBE6540282A0F63F6C044C0849E1738AABE6540C0031434F7C044C0B412A91FAABE6540F094698FF2C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705569, 0x47100000010407000000E4A388B69ABE654018DD35796EC144C0A8A89FDC9BBE654058C50A6D6FC144C0A4ED6C839BBE6540606CBA9B70C144C05C0EF4509BBE654008B3CB1570C144C094CB17659ABE654020C6B5EB6FC144C094910E6A9ABE6540A866C06D6EC144C0E4A388B69ABE654018DD35796EC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705589, 0x471000000104050000002C87AEF589BE6540D02039F769C044C0B430B0338ABE6540C02055B975C044C088C606178ABE654028CEEA1A76C044C0607722D789BE6540305ACFFC69C044C02C87AEF589BE6540D02039F769C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705609, 0x471000000104070000006893B6FD8ABE6540C0BDDC6EDCC044C03C5B333E8BBE6540186354AAE8C044C068605D758ABE65405032CDCFE8C044C03410638389BE6540D819F5FCE8C044C0D868EF4289BE654070185BC1DCC044C09898E0348ABE6540F88C5594DCC044C06893B6FD8ABE6540C0BDDC6EDCC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705614, 0x47100000010407000000B0211AD8B8BE6540C850C60C55C044C074BCB843B9BE654078F481424FC044C0147BC3D8BDBE6540D8F3953D52C044C0D46137CCBDBE6540B040EFEB52C044C08C18946EBDBE654048937A0558C044C0AC735655B9BE654080E4DB5D55C044C0B0211AD8B8BE6540C850C60C55C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705618, 0x4710000001040500000078B1231A9CBE654038EF5A9D77C144C02897C62F9CBE6540B0B0ACD677C144C028EB74769BBE6540F896664B7AC144C06430725B9ABE654058F2CE5A77C144C078B1231A9CBE654038EF5A9D77C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705633, 0x4710000001041000000064AF6A558ABE654050DECC8A96C044C0807676E88ABE65400053F5E18FC044C06C02B1118DBE65408066DC768FC044C064B682AB8EBE6540F02FBB278FC044C0241A0CC48EBE6540E81D13CE93C044C0909962138BBE65409829087998C044C02CEE32088BBE6540D06E4A3298C044C048EDEAFA8ABE6540780E0AEF97C044C064E5A4EB8ABE6540E80FD9AF97C044C000257BDA8ABE6540602BFC7497C044C0684E9BC78ABE654050C4273F97C044C09CD028B38ABE654070DEA40E97C044C0805B599D8ABE6540B89123E496C044C078E750868ABE6540C885CABF96C044C0009B446E8ABE6540D072DEA196C044C064AF6A558ABE654050DECC8A96C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705638, 0x[encoded data, 7342 characters])
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705672, 0x47100000010409000000A8C4DD6F90BE65402898CAD819C144C050B6813B90BE6540E82B4DEC0FC144C0B46E0ACB92BE6540E06AF8710FC144C060B5CAFD92BE6540B0CF52680FC144C0E853BA0093BE6540C0A954F80FC144C0C4B6FB0B93BE654088D5241A12C144C02CB82C1A93BE65402001F9CB14C144C06484C43193BE6540901D605519C144C0A8C4DD6F90BE65402898CAD819C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705674, 0x471000000104050000007C749C3BA7BE6540C084311F59C044C0CC683283ABBE6540787BC67457C044C0503B57EFABBE65405802846A5EC044C0E0B3380DA8BE6540E053568C60C044C07C749C3BA7BE6540C084311F59C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705686, 0x47100000010404000000605F909990BE654028A996BE21C144C0048EBA8C91BE654070C8124524C144C0D088A6A790BE65404071B66F24C144C0605F909990BE654028A996BE21C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705690, 0x471000000104090000009004865195BE6540F811696214C144C034C9416995BE6540785089EB18C144C0A4075C5C95BE654090AD7DED18C144C0A8D03C2A95BE6540F8E8B7F618C144C06484C43193BE6540901D605519C144C02CB82C1A93BE65402001F9CB14C144C024AB4E1395BE6540208C276E14C144C020E26D4595BE6540A0F4CA6414C144C09004865195BE6540F811696214C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705802, 0x4710000001040A000000D83E7C4AF2BE6540C06E11186BC144C09095B6BDEFBE6540D89DF3F56AC144C0CC823FB2EFBE6540D009DF9D6AC144C028CE8EAAEFBE6540A01704426AC144C000B59F2CEFBE6540788DBD1467C144C080B5882DEFBE654050E433ED63C144C090C48E70F1BE654038D5660B64C144C0DC457A4CF2BE6540B04BDC1664C144C028E7D54AF2BE654088B356126BC144C0D83E7C4AF2BE6540C06E11186BC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705826, 0x471000000104090000005412E631CBBE65404875EB4961C144C06CFB2B1FCABE6540E060B43669C144C06C51FE9FC7BE6540E8190CBF65C144C0C41E8C38CABE6540B8D90EFC5EC144C0045F2C67CABE6540F856F07D5FC144C0E43E8397CABE6540F0BCF4F95FC144C074E675C9CABE654010C0177060C144C0C014F2FCCABE6540082A39E060C144C05412E631CBBE65404875EB4961C144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705832, 0x471000000104120000003479D794CCBE6540C0FCBF315EC144C000C063D8CEBE6540B010C24854C144C090F1DA05D0BE6540C0327B4854C144C058140E6ECFBE6540C85B09385FC144C0F88AAB20CFBE6540186C7E575FC144C074BC9AEDCEBE65405845D5685FC144C0805E5DBACEBE654038FC73735FC144C02408FC86CEBE654030DC5E775FC144C0C8B19A53CEBE6540A83D6F745FC144C05C335420CEBE65405024EE6A5FC144C064443AEDCDBE654090E8B45A5FC144C0B06671BACDBE6540F0D5C7435FC144C0DCA70188CDBE6540B82247265FC144C050000F56CDBE6540B8F434025FC144C0F4B0AB24CDBE6540C8CDB5D75EC144C0C091F2F3CCBE65404006A3A65EC144C0BCD0F4C3CCBE6540E8A1456F5EC144C03479D794CCBE6540C0FCBF315EC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705835, 0x47100000010416000000FC5573C5A4BE6540C82EC25B7AC144C040E4E3C9A4BE6540988E2D5C7AC144C05C34AEC9A4BE654000E65F6D7AC144C0C86BCABAA4BE6540A05BED037EC144C0ACE6EF94A4BE6540F0F1AE1F87C144C01CE25C199DBE6540E87B5C0786C144C0444E15429DBE6540E0C25F387CC144C0F4AB2C169EBE654038F58D577CC144C0B8748F169EBE6540C89BB7427CC144C0C019941A9EBE654058FACB4C7BC144C0F40AED979DBE65407087EDF179C144C0205D4E049FBE6540786FA01B75C144C0BCBA0CFAA0BE6540509765527AC144C080836FFAA0BE654010DE233D7AC144C0EC0DAD04A1BE654010B69AD377C144C084F2881BA1BE654068B4F5D677C144C0607DA4D7A2BE6540702F5D1978C144C04C17FA11A3BE654018034BAB6AC144C0BC5E0206A5BE65405000D6F46AC144C05C21B9F0A4BE6540881DE8FC6FC144C0FC7C87E7A4BE6540081C53C172C144C0FC5573C5A4BE6540C82EC25B7AC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705839, 0x471000000104070000006C4D5F749EBE65405847E92DF9C044C0A4911DBB9EBE654088E0694607C144C0E4C09EBB9CBE6540202DC2A507C144C0B4D2E1779CBE6540E070E19EF9C044C0E0DB6D779CBE654008D8B38CF9C044C06CF4D6659DBE6540382E3E60F9C044C06C4D5F749EBE65405847E92DF9C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705852, 0x47100000010406000000C0E6CEAC92BE6540B8C788FA93C044C01CAF33CA92BE6540407F468E99C044C078BF65A990BE6540708EEBF399C044C02CD828E68EBE65409864CE479AC044C0CC0FC4C88EBE6540382BECB394C044C0C0E6CEAC92BE6540B8C788FA93C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705886, 0x4710000001040600000034B8A003EABE654018698C1D67C044C01802CAF0E9BE654098AA9EE063C044C0682325DDE9BE65402819EF7D60C044C03C771618EDBE6540F08D10D45FC044C080FAC270EDBE6540F004566966C044C034B8A003EABE654018698C1D67C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705887, 0x4710000001040600000024B12BCDC0BE654058ACF70749C044C078EFA831C1BE654060B1374548C044C05812F75DC3BE6540F83CC4AE49C044C04CA8E0F0C2BE654098C575A04FC044C0A894E876C0BE654020F69DBA4DC044C024B12BCDC0BE654058ACF70749C044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705892, 0x471000000104090000004CAE55C7C9BE6540507A7F866EC144C09C96F035C8BE654040B950406DC144C0CC00AF80C6BE65408055DF0D6AC144C0C4511041C7BE654070DE82B666C144C06C51FE9FC7BE6540E8190CBF65C144C06CFB2B1FCABE6540E060B43669C144C05412E631CBBE65404875EB4961C144C09C4B7E7FCBBE654028CE9BD461C144C04CAE55C7C9BE6540507A7F866EC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705902, 0x47100000010409000000281E06A9CABE654090D96567ADC144C0882146C3CABE6540003BE826B2C144C018D52FCCCABE6540086BFCBFB3C144C0C459D4D1C8BE6540B8FBC61EB4C144C0B45DFCC8C8BE654000C86985B2C144C0788A66AFC8BE654068E80BC6ADC144C0A4A14621C9BE6540F054CCB0ADC144C010520141CABE6540E0EDF77AADC144C0281E06A9CABE654090D96567ADC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705915, 0x47100000010425000000743A4266D4BE6540C8D8BAE82CC144C0ACFFDB7BD4BE6540C00429092DC144C0EC5B7E91D4BE6540805699292DC144C04C99C7A6D4BE6540B0236E4B2DC144C064BF93BBD4BE654088D3A46F2DC144C0280C14C2D4BE6540502FF37B2DC144C0E8A9A6D5D4BE6540B0969BA52DC144C0F4A08FE8D4BE654058C235D22DC144C038CF15FBD4BE6540204BC4002EC144C0106E6F0DD5BE6540A01105302EC144C0D44DDB1FD5BE654030FAFE5E2EC144C0BCFD1020D5BE6540F8596A5F2EC144C06824BB32D5BE6540D8266B8D2EC144C094027745D5BE6540306EFEBA2EC144C01CB17158D5BE6540F0F5BAE72EC144C07CE7BC6BD5BE65406080EE122FC144C034215278D5BE654008957F2D2FC144C0AC5F628CD5BE654000A37C552FC144C08074DDA0D5BE6540F8AFA77B2FC144C010BBB2B5D5BE6540E8BB00A02FC144C00800D8CAD5BE6540604CF5C22FC144C05C153CE0D5BE6540B897A5E42FC144C0E06428E2D5BE6540403695E72FC144C044397AF7D5BE654060A7470930C144C078670B0DD6BE654018F9B72930C144C0A89BC822D6BE6540A0A9C14830C144C0B8DAB634D6BE6540683B5C6130C144C03020C54AD6BE6540E8EA937E30C144C018F5FF60D6BE6540D0A08B9A30C144C078EA4377D6BE654020D115B630C144C0A0C10188D6BE6540E026A3CA30C144C0B8CAAB24D6BE65400038FBA533C144C0A056693CD5BE6540F0851F553AC144C0706A6396D4BE6540A8AB478939C144C0D4CE876CD2BE6540187CE42032C144C09CB3D601D4BE6540703216F22DC144C0743A4266D4BE6540C8D8BAE82CC144C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
INSERT [qgis_test].[invalid_polys] ([id], [ogr_geometry]) VALUES (3705938, 0x47100000010405000000748C75BBA8BE654098EF25FCAEC044C010A90134AEBE6540D816E36BABC044C0E4B4B40EAFBE65405095162BB3C044C0709E8FD7A8BE654048E5924FB4C044C0748C75BBA8BE654098EF25FCAEC044C001000000020000000002000000FFFFFFFF0000000006000000000000000003)
GO
SET IDENTITY_INSERT [qgis_test].[invalid_polys] OFF
GO

-- Provider check with compound key

CREATE TABLE [qgis_test].[someDataCompound] (
    pk integer NOT NULL,
    cnt integer,
    name nvarchar(max) DEFAULT 'qgis',
    name2 nvarchar(max) DEFAULT 'qgis',
    num_char nvarchar(max),
    dt datetime,
    "date" date,
    "time" time,
    geom geometry,
    key1 integer,
    key2 integer,
    PRIMARY KEY(key1, key2)
);

INSERT INTO [qgis_test].[someDataCompound] ( key1, key2, pk, cnt, name, name2, num_char, dt, "date", "time", geom) VALUES
(1, 1, 5, -200, NULL, 'NuLl', '5', '2020-05-04 12:13:14', '2020-05-02', '12:13:01', geometry::STGeomFromText('POINT(-71.123 78.23)', 4326)),
(1, 2, 3,  300, 'Pear', 'PEaR', '3', NULL, NULL, NULL, NULL),
(2, 1, 1,  100, 'Orange', 'oranGe', '1', '2020-05-03 12:13:14', '2020-05-03', '12:13:14', geometry::STGeomFromText('POINT(-70.332 66.33)', 4326)),
(2, 2, 2,  200, 'Apple', 'Apple', '2', '2020-05-04 12:14:14', '2020-05-04', '12:14:14', geometry::STGeomFromText('POINT(-68.2 70.8)', 4326)),
(2, 3, 4,  400, 'Honey', 'Honey', '4', '2021-05-04 13:13:14', '2021-05-04', '13:13:14', geometry::STGeomFromText('POINT(-65.32 78.3)', 4326));
GO


CREATE TABLE [qgis_test].[tb_test_compound_pk]
(
    pk1 integer,
    pk2 bigint,
    value nvarchar(16),
    geom geometry,
    PRIMARY KEY (pk1, pk2)
);

INSERT INTO [qgis_test].[tb_test_compound_pk] (pk1, pk2, value, geom) VALUES
(1, 1, 'test 1', geometry::STGeomFromText('POINT(-47.930 -15.818)', 4326)),
(1, 2, 'test 2', geometry::STGeomFromText('POINT(-47.887 -15.864)', 4326)),
(2, 1, 'test 3', geometry::STGeomFromText('POINT(-47.902 -15.763)', 4326)),
(2, 2, 'test 4', geometry::STGeomFromText('POINT(-47.952 -15.781)', 4326));
GO

CREATE TABLE [qgis_test].[tb_test_composite_float_pk]
(
    pk1 integer,
    pk2 bigint,
    pk3 real,
    value nvarchar(16),
    geom geometry,
    PRIMARY KEY (pk1, pk2, pk3)
);

INSERT INTO [qgis_test].[tb_test_composite_float_pk] (pk1, pk2, pk3, value, geom) VALUES
    (1, 1, 1.0,         'test 1', geometry::STGeomFromText('POINT(-47.930 -15.818)', 4326)),
    (1, 2, 3.141592741, 'test 2', geometry::STGeomFromText('POINT(-47.887 -15.864)', 4326)),
    (2, 2, 2.718281828, 'test 3', geometry::STGeomFromText('POINT(-47.902 -15.763)', 4326)),
    (2, 2, 1.0,         'test 4', geometry::STGeomFromText('POINT(-47.952 -15.781)', 4326));
GO

-- Table for constraint tests
CREATE TABLE [qgis_test].[constraints]
(
  gid integer PRIMARY KEY,
  val int,
  name text NOT NULL,
  description text,
  CONSTRAINT constraint_val UNIQUE (val)
);
GO

