Stage 6 (MARS, collations, Agent, spatial, backup)
MARS, collations and code pages, SQL Agent schedules that fire, geometry and geography, BACKUP and RESTORE, column permissions, KILL.
The spatial values use the serialization of Microsoft.SqlServer.Types 16; MARS and code pages work with System.Data.SqlClient.
MARS (crate raftdb-tds, smp.rs). MultipleActiveResultSets=True and ODBC's MARS_Connection=yes work: the PRELOGIN answer says MARS on, then every byte is an SMP frame (SYN / ACK / FIN / DATA with sequence numbers and a window of 4). The connection reads frames while replies wait for the client's window, so a reader that is open on a big result and a second command do not block each other. One engine session serves all logical sessions of the connection. A 3000-row reader with a second reader, a scalar, an insert, a transaction and an error work through the same connection, and two readers can be read in turn; mssql-django runs without a workaround. Not done: rows of two replies are not interleaved row by row; a request cannot be cancelled while it runs under MARS; RAFTDB_TDS_NOMARS=1 answers MARS off. RAFTDB_TDS_TRACE=1 prints the frames.
Collations and code pages (collate.rs). COLLATE on a column (CREATE TABLE, ALTER COLUMN), an expression (x COLLATE Latin1_General_CS_AS, DATABASE_DEFAULT) and a database (CREATE DATABASE d COLLATE Czech_CS_AS). Names: Latin1_General (also _90 / _100), SQL_Latin1_General_CP1 / CP437 / CP850 / CP1250 / CP1251, Danish_Norwegian, Czech, Turkish, Cyrillic_General, Polish, French, German_PhoneBook, each with _CI_AS, _CI_AI, _CS_AS, _CS_AI, _BIN, _BIN2 (_KS, _WS, _SC read and ignored; anything else, _UTF8 too, is error 448). Equality, <>, <, >, <=, >=, IN, BETWEEN, ORDER BY, GROUP BY follow the collation (case, accent, binary, and the alphabets of Danish, Czech and Turkish: ch after h, aa as a-ring, dotless i); LIKE follows its case sensitivity; two columns of different collations compared are error 468; varchar columns go out in the code page of their collation (437, 850, 1250, 1251, 1252, 1254) and a text column of another collation than the default announces it in its type information. DATABASEPROPERTYEX('db', 'Collation'), COLLATIONPROPERTY, sys.fn_helpcollations(), sys.columns.collation_name, sys.databases.collation_name, INFORMATION_SCHEMA.COLUMNS.COLLATION_NAME / CHARACTER_SET_NAME. Differences: LIKE of accent-insensitive collations, CHARINDEX, REPLACE, PATINDEX and the other string functions, DISTINCT and UNION of case-sensitive columns, UNIQUE and primary keys of a case-sensitive column ('a' and 'A' collide) are the engine's; CS_AI is CS_AS; BIN is BIN2; the default collation's ORDER BY is the engine's code point order; other Windows collations are error 448.
SQL Agent that fires (agent.rs). raftdb-mssql runs an agent thread: every second it starts the jobs whose enabled schedule is due, each in a session opened as the job's owner (@owner_login_name, else the login that made the job). Frequencies: once, daily every N days, weekly (day mask, every N weeks), monthly on a day, monthly relative (first to fourth and last), at a time or every N seconds / minutes / hours between two times, active date range, when the agent starts; sp_update_schedule, sp_detach_schedule, sp_help_schedule, sp_help_jobschedule, sp_stop_job (a running scheduled job: its WAITFOR ends, history status 3), history in msdb.dbo.sysjobhistory (a row per step and one for the job), msdb.dbo.sysschedules with all fields. sp_start_job still runs the job in the caller's session and returns at its end. Times are UTC. Not done: other subsystems than TSQL, retries, alerts, runs missed while the process was down.
geometry and geography (spatial.rs). geometry::STGeomFromText(wkt, srid), geometry::Point(x, y, srid), geography::Point(lat, long, srid), Parse, STGeomFromWKB and the methods STAsText, STAsBinary, ToString, STSrid, STX, STY, Lat, Long, STGeometryType, STDimension, STNumPoints, STNumGeometries, STIsEmpty, STIsValid, STArea, STLength, STDistance, STContains, STWithin, STIntersects, STDisjoint, STEquals, STTouches, STCrosses, STOverlaps, STEnvelope, STCentroid, STStartPoint, STEndPoint, STPointN, STGeometryN, STExteriorRing, STInteriorRingN, STUnion, STIntersection, STDifference, STSymDifference, STConvexHull, written as value.Method(args) and type::Method(args) (also on variables, parenthesised values and call results; a property as p.STX). STBuffer, BufferWithTolerance, Reduce, MakeValid and the rest are refused (40000). Columns and variables hold the engine's geometry. On the wire the type is TDS 0xF0 (sys.geometry / sys.geography) and the value is the native serialization of Microsoft.SqlServer.Types; System.Data.SqlClient returns SqlGeometry / SqlGeography objects and accepts a SqlGeometry parameter. Differences: planar and two-dimensional only; STDistance of geography is the great-circle distance in metres on the 6371008.77 m sphere for points (up to 0.5 % from SQL Server's ellipsoid); STLength of a polygon is its exterior ring; invalid WKT is NULL; the Microsoft JDBC driver's Geometry class was not tried; hierarchyid is not built.
BACKUP / RESTORE (backup.rs). With --backup-dir DIR: BACKUP DATABASE d TO DISK = 'nightly.backup' [WITH INIT, COMPRESSION, CHECKSUM, STATS, NAME, DESCRIPTION, ...] writes a file under DIR (the definitions and rows of every table of the database, the front-end's own tables included, views, engine triggers, the collation); RESTORE DATABASE d FROM DISK = 'nightly.backup' [WITH REPLACE] replaces the database; RESTORE VERIFYONLY. A path outside DIR, .. in a path, or no --backup-dir is error 3201 (Operating system error 5(Access is denied.)). Not in a backup: the history of temporal tables, the position of sequences, other databases, logins, jobs. Differential, log, file, filegroup backups, other devices and RESTORE HEADERONLY / FILELISTONLY / LABELONLY are refused (40000).
Column permissions. GRANT | DENY | REVOKE SELECT | UPDATE | REFERENCES ON t (cols) TO user are kept and enforced: a statement that names a column without the permission is error 229, a column DENY wins over a table GRANT, UPDATE needs UPDATE on the assigned columns and SELECT on the others it reads. The check reads the column names of the translated statement.
KILL, requests, identity, defaults, schemas. KILL n ends a running request of another session and the session's next request is error 596 (severity 21, the connection closes; severity 20 and above closes the connection in raftdb-tds); sys.dm_exec_requests lists every session that is running a request; DBCC CHECKIDENT (t, RESEED, n) moves the engine's counter (one edit in raftdb-mysql); CONSTRAINT DF_x DEFAULT ... and ADD CONSTRAINT DF_x DEFAULT ... FOR col show by name in sys.default_constraints (DROP CONSTRAINT of a default is still 3728); INFORMATION_SCHEMA.TABLES, COLUMNS and TABLE_CONSTRAINTS show the schema of a table and GRANT ... ON SCHEMA::hr covers hr only.
Run. raftdb-mssql ... [--import-dir DIR] [--backup-dir DIR].