示例#1
0
        private void createDefaultTable(string testTable, List <ColumnMetadata> metadata)
        {
            SqlClient sqlClient = getClient() as SqlClient;

            deleteTable(sqlClient, testTable);

            string sqlCommand;

            sqlCommand = "CREATE TABLE " + testTable + " (";
            foreach (ColumnMetadata cmd in metadata)
            {
                sqlCommand += "[" + cmd.Fieldname + "] [" + cmd.Typename + "]" + cmd.Size + " ";
                if (!cmd.IsNullable)
                {
                    sqlCommand += "NOT NULL";
                }
                sqlCommand += ",";
            }
            sqlCommand += ")";

            sqlClient.ExecuteNonQueryCommand(sqlCommand);
        }
示例#2
0
        public void T06_ColumnMetaDataHandling()
        {
            SqlClient sqlClient = (SqlClient)getClient();

            // Create a small Column meta data list, one column to play with and
            // the other so there is at least one valid column.
            List <ColumnMetadata> cm = new List <ColumnMetadata>();

            cm.Add(new ColumnMetadata() // used to play around with
            {
                Typename  = "decimal",
                Fieldname = "MyDecimal",
            });
            cm.Add(new ColumnMetadata() // make sure one value is there
            {
                Typename  = "ntext",
                Fieldname = "MyText",
            });
            string           table = "_tmpTable";
            List <SqlColumn> columns;

            //  Read property from table
            cm[0].IsNullable = true;
            createDefaultTable(table, cm);
            columns = sqlClient.GetColumns(table);
            Assert.IsTrue(columns[0].IsNullable);

            cm[0].IsNullable = false;
            createDefaultTable(table, cm);
            columns = sqlClient.GetColumns(table);
            Assert.IsFalse(columns[0].IsNullable);

            // Test value conversion (nullable)
            cm[0].IsNullable = true;
            createDefaultTable(table, cm);
            columns = sqlClient.GetColumns(table);
            columns[0].ValueString = null;
            columns[1].ValueString = "Hello World";

            sqlClient.SetObjectValues(columns); // make sure no exception
            sqlClient.Insert(columns, table);   // insertion should work

            // Test value conversion (not nullable)
            cm[0].IsNullable = false;
            createDefaultTable(table, cm);
            columns = sqlClient.GetColumns(table);
            columns[0].ValueString = null;
            columns[1].ValueString = "Hello World";

            bool exception = false;

            try { sqlClient.SetObjectValues(columns); } // conversion should fail
            catch { exception = true; }
            Assert.IsTrue(exception);

            columns[0].IsNullable = true;   // force conversion to succeed
            sqlClient.SetObjectValues(columns);

            try { sqlClient.Insert(columns, table); }   // insertion must fail now
            catch { exception = true; }
            Assert.IsTrue(exception);

            deleteTable(sqlClient, table);
        }
示例#3
0
 private void t01_connect(SqlClient sqlClient, ConnectionDefinition cd)
 {
     sqlClient.Connect(cd.Instance, cd.Database, cd.Username, cd.Password);
 }