You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
4
4
### Features
5
5
6
+
* Add native JSON type support for SQL Server 2025 Preview. The driver now negotiates JSON support during TDS login and properly handles the new JSON data type (0xF4). JSON data is decoded using the NVARCHAR string path and returned as `string`; it can be scanned into `string`, `[]byte`, `mssql.NullJSON`, or types implementing `sql.Scanner`.
6
7
* Added new `serverCertificate` connection parameter for byte-for-byte certificate validation, matching Microsoft.Data.SqlClient behavior. This parameter skips hostname validation, chain validation, and expiry checks, only verifying that the server's certificate exactly matches the provided file. This is useful when the server's hostname doesn't match the certificate CN/SAN. (#304)
7
8
* The existing `certificate` parameter maintains backward compatibility with traditional X.509 chain validation including hostname checks, expiry validation, and chain-of-trust verification.
8
9
*`serverCertificate` cannot be used with `certificate` or `hostnameincertificate` parameters to prevent conflicting validation methods.
Copy file name to clipboardExpand all lines: README.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -492,6 +492,8 @@ are supported:
492
492
493
493
* string -> nvarchar
494
494
* mssql.VarChar -> varchar
495
+
* mssql.JSON -> json (SQL Server2025+) or nvarchar(max) (older versions)
496
+
* mssql.NullJSON -> json (nullable, SQLServer2025+) or nvarchar(max) (older versions)
495
497
* time.Time -> datetimeoffset or datetime (TDS version dependent)
496
498
* mssql.DateTime1 -> datetime
497
499
* mssql.DateTimeOffset -> datetimeoffset
@@ -515,6 +517,41 @@ db.QueryContext(ctx, `select * from t2 where user_name = @p1;`, mssql.VarChar(na
515
517
// Note: Mismatched data types on table and parameter may cause long running queries
516
518
```
517
519
520
+
### JSONType
521
+
522
+
The driver provides `mssql.JSON` and `mssql.NullJSON` types for working with JSON data. These types work seamlessly across all supported SQLServer versions with automatic fallback behavior.
523
+
524
+
**Server Compatibility:**
525
+
- **SQL Server2025+ / AzureSQLDatabase**: Uses the native JSON data type (typeID0xF4) for optimal performance and type safety
526
+
- **SQL Server2016-2022**: Automatically falls back to `nvarchar(max)` parameter declaration, allowing JSON data to work with the built-in JSONfunctions (JSON_VALUE, JSON_QUERY, ISJSON, etc.)
527
+
528
+
The driver automatically detects server capabilities during connection and chooses the appropriate behavior. You can use the same `mssql.JSON` and `mssql.NullJSON` types regardless of the SQLServer version - no code changes required.
529
+
530
+
**Note:** NativeJSON *columns* (using the JSON data type in CREATETABLE) require SQLServer2025+ or AzureSQLDatabase. On older versions, store JSON in `nvarchar(max)` columns.
err = db.QueryRowContext(ctx, "SELECT metadata FROM users WHERE id = @p1", 1).Scan(&result)
548
+
if result.Valid {
549
+
fmt.Println("JSON data:", result.JSON)
550
+
} else {
551
+
fmt.Println("JSON is NULL")
552
+
}
553
+
```
554
+
518
555
## UsingAlwaysEncrypted
519
556
520
557
The protocol and cryptography details forAE are [detailed elsewhere](https://learn.microsoft.com/sql/relational-databases/security/encryption/always-encrypted-database-engine?view=sql-server-ver16).
@@ -590,6 +627,7 @@ Constrain the provider to an allowed list of key vaults by appending vault host
590
627
* Can be used with MicrosoftAzureSQLDatabase
591
628
* Can be used on all go supported platforms (e.g. Linux, MacOSX and Windows)
592
629
* Supports new date/time types: date, time, datetime2, datetimeoffset
630
+
* SupportsJSON data with automatic fallback (SQL Server2016+, native JSONtype in 2025+)
593
631
* Supportsstring parameters longer than 8000 characters
594
632
* Supports encryption using SSL/TLS
595
633
* SupportsSQLServer and WindowsAuthentication
@@ -647,6 +685,8 @@ More information: <http://support.microsoft.com/kb/2653857>
647
685
648
686
* Bulk copy does not yet support encrypting column values using Always Encrypted. Tracked in [#127](https://github.com/microsoft/go-mssqldb/issues/127)
649
687
688
+
* The JSON data type is not supported with Always Encrypted. This is a SQL Server limitation - the JSON type is not included in the list of [supported data types for Always Encrypted](https://learn.microsoft.com/en-us/sql/relational-databases/security/encryption/always-encrypted-cryptography).
689
+
650
690
# Contributing
651
691
This project is a fork of [https://github.com/denisenkom/go-mssqldb](https://github.com/denisenkom/go-mssqldb) and welcomes new and previous contributors. For more informaton on contributing to this project, please see [Contributing](./CONTRIBUTING.md).
0 commit comments