Skip to content

Commit ab34ba2

Browse files
committed
Add MSSQL test suite
1 parent f42dabb commit ab34ba2

File tree

5 files changed

+192
-1
lines changed

5 files changed

+192
-1
lines changed

scalasql/src/dialects/MsSqlDialect.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import scalasql.operations
55
import scalasql.core.SqlStr.SqlStringSyntax
66
import scalasql.operations.{ConcatOps, MathOps, TrimOps}
77

8+
import java.time.{Instant, LocalDateTime, OffsetDateTime}
9+
810
trait MsSqlDialect extends Dialect {
911
protected def dialectCastParams = false
1012

@@ -14,6 +16,25 @@ trait MsSqlDialect extends Dialect {
1416
override implicit def StringType: TypeMapper[String] = new MsSqlStringType
1517
class MsSqlStringType extends StringType { override def castTypeString = "VARCHAR" }
1618

19+
override implicit def BooleanType: TypeMapper[Boolean] = new BooleanType
20+
class MsSqlBooleanType extends BooleanType { override def castTypeString = "BIT" }
21+
22+
override implicit def UtilDateType: TypeMapper[java.util.Date] = new MsSqlUtilDateType
23+
class MsSqlUtilDateType extends UtilDateType { override def castTypeString = "DATETIME2" }
24+
25+
override implicit def LocalDateTimeType: TypeMapper[LocalDateTime] = new MsSqlLocalDateTimeType
26+
class MsSqlLocalDateTimeType extends LocalDateTimeType {
27+
override def castTypeString = "DATETIME2"
28+
}
29+
30+
override implicit def InstantType: TypeMapper[Instant] = new MsSqlInstantType
31+
class MsSqlInstantType extends InstantType { override def castTypeString = "DATETIME2" }
32+
33+
override implicit def OffsetDateTimeType: TypeMapper[OffsetDateTime] = new MsSqlOffsetDateTimeType
34+
class MsSqlOffsetDateTimeType extends OffsetDateTimeType {
35+
override def castTypeString = "DATETIMEOFFSET"
36+
}
37+
1738
override implicit def ExprStringOpsConv(v: Expr[String]): MsSqlDialect.ExprStringOps[String] =
1839
new MsSqlDialect.ExprStringOps(v)
1940

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'shipping_info')
2+
ALTER TABLE shipping_info DROP CONSTRAINT IF EXISTS fk_shipping_info_buyer;
3+
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'purchase')
4+
ALTER TABLE purchase DROP CONSTRAINT IF EXISTS fk_purchase_shipping_info;
5+
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'purchase')
6+
ALTER TABLE purchase DROP CONSTRAINT IF EXISTS fk_purchase_product;
7+
DROP TABLE IF EXISTS buyer;
8+
DROP TABLE IF EXISTS product;
9+
DROP TABLE IF EXISTS shipping_info;
10+
DROP TABLE IF EXISTS purchase;
11+
DROP TABLE IF EXISTS data_types;
12+
DROP TABLE IF EXISTS non_round_trip_types;
13+
DROP TABLE IF EXISTS opt_cols;
14+
DROP TABLE IF EXISTS nested;
15+
DROP TABLE IF EXISTS enclosing;
16+
DROP TABLE IF EXISTS invoice;
17+
-- DROP SCHEMA IF EXISTS otherschema;
18+
19+
CREATE TABLE buyer (
20+
id INT PRIMARY KEY IDENTITY(1, 1),
21+
name VARCHAR(256),
22+
date_of_birth DATE
23+
);
24+
25+
CREATE TABLE product (
26+
id INT PRIMARY KEY IDENTITY(1, 1),
27+
kebab_case_name VARCHAR(256),
28+
name VARCHAR(256),
29+
price DECIMAL(20, 2)
30+
);
31+
32+
CREATE TABLE shipping_info (
33+
id INT PRIMARY KEY IDENTITY(1, 1),
34+
buyer_id INT,
35+
shipping_date DATE,
36+
CONSTRAINT fk_shipping_info_buyer
37+
FOREIGN KEY(buyer_id) REFERENCES buyer(id)
38+
);
39+
40+
CREATE TABLE purchase (
41+
id INT PRIMARY KEY IDENTITY(1, 1),
42+
shipping_info_id INT,
43+
product_id INT,
44+
count INT,
45+
total DECIMAL(20, 2),
46+
CONSTRAINT fk_purchase_shipping_info
47+
FOREIGN KEY(shipping_info_id) REFERENCES shipping_info(id),
48+
CONSTRAINT fk_purchase_product
49+
FOREIGN KEY(product_id) REFERENCES product(id)
50+
);
51+
52+
CREATE TABLE data_types (
53+
my_tiny_int TINYINT,
54+
my_small_int SMALLINT,
55+
my_int INT,
56+
my_big_int BIGINT,
57+
my_double FLOAT(53),
58+
my_boolean BIT,
59+
my_local_date DATE,
60+
my_local_time TIME,
61+
my_local_date_time DATETIME2,
62+
my_util_date DATETIMEOFFSET,
63+
my_instant DATETIMEOFFSET,
64+
my_var_binary VARBINARY,
65+
my_uuid UNIQUEIDENTIFIER,
66+
my_enum VARCHAR(256)
67+
-- my_offset_time TIME WITH TIME ZONE,
68+
69+
);
70+
71+
CREATE TABLE non_round_trip_types(
72+
my_zoned_date_time DATETIMEOFFSET,
73+
my_offset_date_time DATETIMEOFFSET
74+
);
75+
76+
CREATE TABLE opt_cols(
77+
my_int INT,
78+
my_int2 INT
79+
);
80+
81+
CREATE TABLE nested(
82+
foo_id INT,
83+
my_boolean BIT
84+
);
85+
86+
CREATE TABLE enclosing(
87+
bar_id INT,
88+
my_string VARCHAR(256),
89+
foo_id INT,
90+
my_boolean BIT
91+
);
92+
93+
94+
-- CREATE SCHEMA otherschema;
95+
96+
-- CREATE TABLE otherschema.invoice(
97+
-- id PRIMARY KEY IDENTITY(1, 1),
98+
-- total DECIMAL(20, 2),
99+
-- vendor_name VARCHAR(256)
100+
-- );

scalasql/test/src/ConcreteTestSuites.scala

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ import scalasql.dialects.{
3535
MySqlDialectTests,
3636
PostgresDialectTests,
3737
SqliteDialectTests,
38-
H2DialectTests
38+
H2DialectTests,
39+
MsSqlDialectTests
3940
}
4041

4142
package postgres {
@@ -267,3 +268,48 @@ package h2 {
267268

268269
object H2DialectTests extends H2DialectTests
269270
}
271+
272+
package mssql {
273+
274+
import utils.MsSqlSuite
275+
276+
object DbApiTests extends DbApiTests with MsSqlSuite
277+
object TransactionTests extends TransactionTests with MsSqlSuite
278+
279+
object SelectTests extends SelectTests with MsSqlSuite
280+
object JoinTests extends JoinTests with MsSqlSuite
281+
object FlatJoinTests extends FlatJoinTests with MsSqlSuite
282+
object InsertTests extends InsertTests with MsSqlSuite
283+
object UpdateTests extends UpdateTests with MsSqlSuite
284+
object DeleteTests extends DeleteTests with MsSqlSuite
285+
object CompoundSelectTests extends CompoundSelectTests with MsSqlSuite
286+
object UpdateJoinTests extends UpdateJoinTests with MsSqlSuite
287+
object UpdateSubQueryTests extends UpdateSubQueryTests with MsSqlSuite
288+
// object ReturningTests extends ReturningTests with MsSqlSuite
289+
// object OnConflictTests extends OnConflictTests with MsSqlSuite
290+
object ValuesTests extends ValuesTests with MsSqlSuite
291+
// object LateralJoinTests extends LateralJoinTests with MsSqlSuite
292+
object WindowFunctionTests extends WindowFunctionTests with MsSqlSuite
293+
object GetGeneratedKeysTests extends GetGeneratedKeysTests with MsSqlSuite
294+
object SchemaTests extends SchemaTests with MsSqlSuite
295+
296+
object SubQueryTests extends SubQueryTests with MsSqlSuite
297+
object WithCteTests extends WithCteTests with MsSqlSuite
298+
299+
object DbApiOpsTests extends DbApiOpsTests with MsSqlSuite
300+
object ExprOpsTests extends ExprOpsTests with MsSqlSuite
301+
object ExprBooleanOpsTests extends ExprBooleanOpsTests with MsSqlSuite
302+
object ExprNumericOpsTests extends ExprNumericOpsTests with MsSqlSuite
303+
object ExprSeqNumericOpsTests extends ExprAggNumericOpsTests with MsSqlSuite
304+
object ExprSeqOpsTests extends ExprAggOpsTests with MsSqlSuite
305+
object ExprStringOpsTests extends ExprStringOpsTests with MsSqlSuite
306+
object ExprBlobOpsTests extends ExprBlobOpsTests with MsSqlSuite
307+
object ExprMathOpsTests extends ExprMathOpsTests with MsSqlSuite
308+
309+
object DataTypesTests extends datatypes.DataTypesTests with MsSqlSuite
310+
311+
object OptionalTests extends datatypes.OptionalTests with MsSqlSuite
312+
313+
object MsSqlDialectTests extends MsSqlDialectTests
314+
315+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package scalasql.dialects
2+
3+
import scalasql._
4+
import utest._
5+
import utils.MsSqlSuite
6+
7+
trait MsSqlDialectTests extends MsSqlSuite {
8+
def description = "Operations specific to working with Microsoft SQL Databases"
9+
10+
def tests = Tests {}
11+
}

scalasql/test/src/utils/ScalaSqlSuite.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ trait MySqlSuite extends ScalaSqlSuite with MySqlDialect {
8383

8484
checker.reset()
8585
}
86+
87+
trait MsSqlSuite extends ScalaSqlSuite with MsSqlDialect {
88+
val checker = new TestChecker(
89+
scalasql.example.MsSqlExample.mssqlClient,
90+
"mssql-customer-schema.sql",
91+
"customer-data.sql",
92+
getClass.getName,
93+
suiteLine.value,
94+
description
95+
)
96+
97+
checker.reset()
98+
}

0 commit comments

Comments
 (0)