16 using System.Collections.Generic;
24 using NUnit.Framework;
26 namespace Deveel.Data.Sql.Statements {
31 const string sql =
"CREATE TABLE test (id INT, name VARCHAR)";
33 IEnumerable<SqlStatement> statements = null;
35 Assert.IsNotNull(statements);
37 var list = statements.ToList();
39 Assert.AreEqual(1, list.Count);
41 var statement = list[0];
43 Assert.IsNotNull(statement);
47 Assert.AreEqual(2, createTable.Columns.Count);
49 var columns = createTable.
Columns;
51 Assert.AreEqual(
"id", columns[0].ColumnName);
52 Assert.AreEqual(
SqlTypeCode.Integer, columns[0].ColumnType.TypeCode);
54 Assert.AreEqual(
"name", columns[1].ColumnName);
55 Assert.IsInstanceOf<
StringType>(columns[1].ColumnType);
60 const string sql =
"CREATE TABLE test (id INT, name VARCHAR)";
62 IEnumerable<SqlStatement> statements = null;
64 Assert.IsNotNull(statements);
66 var list = statements.ToList();
68 Assert.AreEqual(1, list.Count);
70 var statement = list[0];
72 Assert.IsNotNull(statement);
76 Assert.DoesNotThrow(() => result = statement.Execute(
Query));
77 Assert.IsNotNull(result);
78 Assert.AreEqual(1, result.RowCount);
83 const string sql =
"CREATE TABLE test (id INT, name VARCHAR DEFAULT (67 * 90)+22, date TIMESTAMP DEFAULT GetDate())";
85 IEnumerable<SqlStatement> statements = null;
87 Assert.IsNotNull(statements);
89 var list = statements.ToList();
91 Assert.AreEqual(1, list.Count);
93 var statement = list[0];
95 Assert.IsNotNull(statement);
99 Assert.DoesNotThrow(() => result = statement.Execute(
Query));
100 Assert.IsNotNull(result);
101 Assert.AreEqual(1, result.RowCount);
106 const string sql =
"CREATE TABLE test (id INT, name VARCHAR DEFAULT (67 * 90)+22, date TIMESTAMP DEFAULT GetDate())";
108 IEnumerable<SqlStatement> statements = null;
110 Assert.IsNotNull(statements);
112 var list = statements.ToList();
114 Assert.AreEqual(1, list.Count);
116 var statement = list[0];
118 Assert.IsNotNull(statement);
122 Assert.AreEqual(3, createTable.Columns.Count);
124 var columns = createTable.
Columns;
126 Assert.AreEqual(
"id", columns[0].ColumnName);
127 Assert.AreEqual(
SqlTypeCode.Integer, columns[0].ColumnType.TypeCode);
129 Assert.AreEqual(
"name", columns[1].ColumnName);
130 Assert.IsInstanceOf<
StringType>(columns[1].ColumnType);
131 Assert.IsTrue(columns[1].HasDefaultExpression);
134 Assert.AreEqual(
"date", columns[2].ColumnName);
135 Assert.IsInstanceOf<
DateType>(columns[2].ColumnType);
136 Assert.IsTrue(columns[1].HasDefaultExpression);
142 const string sql =
"CREATE TABLE test (id INT IDENTITY, name VARCHAR NOT NULL)";
144 IEnumerable<SqlStatement> statements = null;
146 Assert.IsNotNull(statements);
148 var list = statements.ToList();
150 Assert.AreEqual(1, list.Count);
152 var statement = list[0];
154 Assert.IsNotNull(statement);
158 Assert.AreEqual(2, createTable.Columns.Count);
160 var columns = createTable.
Columns;
162 Assert.AreEqual(
"id", columns[0].ColumnName);
163 Assert.AreEqual(
SqlTypeCode.Integer, columns[0].ColumnType.TypeCode);
164 Assert.IsNotNull(columns[0].DefaultExpression);
167 Assert.AreEqual(
"name", columns[1].ColumnName);
168 Assert.IsInstanceOf<
StringType>(columns[1].ColumnType);
169 Assert.IsTrue(columns[1].IsNotNull);
174 const string sql =
"CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR NOT NULL)";
176 IEnumerable<SqlStatement> statements = null;
178 Assert.IsNotNull(statements);
180 var list = statements.ToList();
182 Assert.AreEqual(2, list.Count);
187 const string sql =
"CREATE TABLE test (id INT PRIMARY KEY, name VARCHAR NOT NULL, CONSTRAINT uk_test UNIQUE(name))";
189 IEnumerable<SqlStatement> statements = null;
191 Assert.IsNotNull(statements);
193 var list = statements.ToList();
195 Assert.AreEqual(3, list.Count);
Defines the contract to access the data contained into a table of a database.
The statement object used to create a table in a database.
IList< SqlTableColumn > Columns
void ParseWithColumnAndTableConstraints()
Represents the foundation class of SQL statements to be executed.
void ParseWithColumnIdentity()
void ParseWithColumnConstraints()
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
void ParseWithColumnDefault()
static IEnumerable< SqlStatement > Parse(string sqlSource)
Parses a given string into one of more statements.