context: /* SqlTest.cs - based on PostgresTest.cs
   * 
   * Copyright (C) 2002 Gonzalo Paniagua Javier
   * Copyright (C) 2002 Daniel Morgan
   * Copyright (C) 2002 Tim Coleman
   *
   * ORIGINAL AUTHOR:
   *	Gonzalo Paniagua Javier <gonzalo@gnome-db.org>
   * PORTING FROM C TO C# AUTHOR:
   *	Daniel Morgan <danmorg@sc.rr.com>
   * PORTING TO SQL SERVER AUTHOR:
   *	Tim Coleman <tim@timcoleman.com>
   *
   * Permission was given from the original author, Gonzalo Paniagua Javier,
   * to port and include his original work in Mono.
   * 
   * The original work falls under the LGPL, but the port to C# falls
   * under the X11 license.
   * 
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
   * published by the Free Software Foundation; either version 2 of the
   * License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Library General Public License for more details.
   *
   * You should have received a copy of the GNU General Public
   * License along with this program; see the file COPYING.  If not,
   * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   * Boston, MA 02111-1307, USA.
   */
  
  using System;
  using System.Data;
  using System.Data.SqlClient;
  using System.Text;
  
  namespace Test.Mono.Data.SqlClient {
  
  	class SqlTest {
  
  		// execute SQL CREATE TABLE Command using ExecuteNonQuery()
  		static void CreateTable (IDbConnection cnc) {
  						
  			IDbCommand createCommand = cnc.CreateCommand();
  	
  			createCommand.CommandText = 
  				"create table mono_sql_test (" +
  				"bit_value bit, " +
  				"binary_value binary (8), " +
  				"char_value char(50), " +
  				"datetime_value datetime, " +
  				"decimal_value decimal(15, 3), " +
  				"float_value float, " +
  				"image_value image, " +
  				"int_value int, " +
  				"money_value money, " +
  				"nchar_value nchar(50), " +
  				"ntext_value ntext, " +
  				"nvarchar_value nvarchar(20), " +
  				"real_value real, " + 
  				"smalldatetime_value smalldatetime, " +
  				"smallint_value smallint, " +
  				"smallmoney_value smallmoney, " +
  				"text_value text, " +
  				"timestamp_value timestamp, " +
  				"tinyint_value tinyint, " +
  				"uniqueidentifier_value uniqueidentifier, "  +
  				"varbinary_value varbinary (8), " +
  				"varchar_value varchar(20), " +
  				"null_bit_value bit, " +
  				"null_binary_value binary (8), " +
  				"null_char_value char(50), " +
  				"null_datetime_value datetime, " +
  				"null_decimal_value decimal(15, 3), " +
  				"null_float_value float, " +
  				"null_image_value image, " +
  				"null_int_value int, " +
  				"null_money_value int, " +
  				"null_nchar_value nchar(50), " +
  				"null_ntext_value ntext, " +
  				"null_nvarchar_value nvarchar(20), " +
  				"null_real_value real, " + 
  				"null_smalldatetime_value smalldatetime, " +
  				"null_smallint_value smallint, " +
  				"null_smallmoney_value int, " +
  				"null_text_value text, " +
  				"null_tinyint_value tinyint, " +
  				"null_uniqueidentifier_value uniqueidentifier, "  +
  				"null_varbinary_value varbinary (8), " +
  				"null_varchar_value varchar(20) " +
  				")";			
  	
  			createCommand.ExecuteNonQuery ();
  		}
  
  		// execute SQL DROP TABLE Command using ExecuteNonQuery
  		static void DropTable (IDbConnection cnc) {
  				 
  			IDbCommand dropCommand = cnc.CreateCommand ();
  
  			dropCommand.CommandText =
  				"drop table mono_sql_test";
  							
  			dropCommand.ExecuteNonQuery ();
  		}
  
  		// execute stored procedure using ExecuteScalar()
  		static object CallStoredProcedure (IDbConnection cnc) {
  				 
  			IDbCommand callStoredProcCommand = cnc.CreateCommand ();
  			object data;
  
  			callStoredProcCommand.CommandType = 
  				CommandType.StoredProcedure;
  			callStoredProcCommand.CommandText =
  				"sp_server_info";
  							
  			data = callStoredProcCommand.ExecuteScalar ();
  
  			return data;
  		}
  
  		// execute SQL INSERT Command using ExecuteNonQuery()
  		static void InsertData (IDbConnection cnc) {		
  
  			IDbCommand insertCommand = cnc.CreateCommand();
  		
  			insertCommand.CommandText =
  				"insert into mono_sql_test (" +
  				"bit_value, " +
  				"binary_value, " +
  				"char_value, " +
  				"datetime_value, " +
  				"decimal_value, " +
  				"float_value, " +
  				"image_value, " +
  				"int_value, " +
  				"money_value, " +
  				"nchar_value, " +
  				"ntext_value, " +
  				"nvarchar_value, " +
  				"real_value, " + 
  				"smalldatetime_value, " +
  				"smallint_value, " +
  				"smallmoney_value, " +
  				"text_value, " +
  				"tinyint_value, " +
  				"uniqueidentifier_value, " +
  				"varbinary_value, " +
  				"varchar_value " +
  				") values (" +
  				"@p1, " +
  				"@p2, " +
  				"@p3, " +
  				"@p4, " +
  				"@p5, " +
  				"@p6, " +
  				"@p7, " +
  				"@p8, " +
  				"@p9, " +
  				"@p10, " +
  				"@p11, " +
  				"@p12, " +
  				"@p13, " +
  				"@p14, " +
  				"@p15, " +
  				"@p16, " +
  				"@p17, " +
  				"@p18, " +
  				"@p19, " +
  				"@p20, " +
  				"@p21 " +
  				")";
  
  			SqlParameterCollection parameters = ((SqlCommand) insertCommand).Parameters;
  
  			parameters.Add ("@p1",  SqlDbType.Bit);
  			parameters.Add ("@p2",  SqlDbType.Binary, 8);
  			parameters.Add ("@p3",  SqlDbType.Char, 14);
  			parameters.Add ("@p4",  SqlDbType.DateTime);
  			parameters.Add ("@p5",  SqlDbType.Decimal);
  			parameters.Add ("@p6",  SqlDbType.Float);
  			parameters.Add ("@p7",  SqlDbType.Image);
  			parameters.Add ("@p8",  SqlDbType.Int);
  			parameters.Add ("@p9",  SqlDbType.Money);
  			parameters.Add ("@p10", SqlDbType.NChar, 16);
  			parameters.Add ("@p11", SqlDbType.NText);
  			parameters.Add ("@p12", SqlDbType.NVarChar, 19);
  			parameters.Add ("@p13", SqlDbType.Real);
  			parameters.Add ("@p14", SqlDbType.SmallDateTime);
  			parameters.Add ("@p15", SqlDbType.SmallInt);
  			parameters.Add ("@p16", SqlDbType.SmallMoney);
  			parameters.Add ("@p17", SqlDbType.Text);
  			parameters.Add ("@p18", SqlDbType.TinyInt);
  			parameters.Add ("@p19", SqlDbType.UniqueIdentifier);
  			parameters.Add ("@p20", SqlDbType.VarBinary, 8);
  			parameters.Add ("@p21", SqlDbType.VarChar, 17);
  
  			parameters ["@p1"].Value = true;
  			parameters ["@p2"].Value = new byte[2] {0x12,0x34};
  			parameters ["@p3"].Value = "This is a char";
  			parameters ["@p4"].Value = new DateTime (1959, 7, 17); // My mom's birthday!
  
  			parameters ["@p5"].Value = 123456789012.345;
  			parameters ["@p5"].Precision = 15;
  			parameters ["@p5"].Scale = 3;
  
  			parameters ["@p6"].Value = 3.1415926969696;
  			parameters ["@p7"].Value = new byte[4] {0xde, 0xad, 0xbe, 0xef};
  			parameters ["@p8"].Value = 1048000;
  			parameters ["@p9"].Value = 31337.456;
  
gt: 			parameters ["@p10"].Value = "This is an nchar";