ExecuteGenericCommand() public method

Execute a QueryCommand without Paramters
public ExecuteGenericCommand ( IDbCommand command ) : int
command IDbCommand
return int
Example #1
0
		public DbAccessLayer GetWrapper(DbAccessType type)
		{
			if (expectWrapper != null)
			{
				expectWrapper.Database.CloseAllConnection();
			}

			//string dbname = "testDB";
			//var sqlLiteFileName = dbname + ".sqlite";

			var tempPath = Path.GetTempFileName();


			expectWrapper = new DbAccessLayer(DbAccessType, string.Format(ConnectionString, tempPath));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(UsersMeta.CreateSqLite));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(BookMeta.CreateSqLite));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(ImageMeta.CreateSqLite));
			return expectWrapper;
		}
Example #2
0
		public DbAccessLayer GetWrapper(DbAccessType type)
		{
			const string dbname = "testDB";
			if (expectWrapper != null)
			{
				expectWrapper.Database.CloseAllConnection();
			}

			var redesginDatabase = string.Format(
				"IF EXISTS (select * from sys.databases where name=\'{0}\') DROP DATABASE {0}",
				dbname);

			expectWrapper = new DbAccessLayer(DbAccessType, ConnectionString, null, new DbConfig(true));
			try
			{
				expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(string.Format("ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE ", dbname)));
			}
			catch (Exception)
			{
				Console.WriteLine("Db does not exist");
			}

			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(redesginDatabase));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(string.Format("CREATE DATABASE {0}", dbname)));

			expectWrapper = new DbAccessLayer(DbAccessType, string.Format(ConnectionString + "Initial Catalog={0};", dbname));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(UsersMeta.CreateMsSql));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(BookMeta.CreateMsSQl));
			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand(ImageMeta.CreateMsSQl));

			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand("CREATE PROC TestProcA " +
																					 "AS BEGIN " +
																					 "SELECT * FROM Users " +
																					 "END"));

			expectWrapper.ExecuteGenericCommand(expectWrapper.Database.CreateCommand("CREATE PROC TestProcB @bigThen INT " +
																					 "AS BEGIN " +
																					 "SELECT * FROM Users us WHERE @bigThen > us.User_ID " +
																					 "END "));


			return expectWrapper;
		}
		public static void ClearDb(DbAccessLayer mgr)
		{
			mgr.Config.Dispose();
			DbConfig.Clear();
			if (mgr.DbAccessType == DbAccessType.MsSql)
			{
				mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", UsersMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", ImageMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", BookMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("TRUNCATE TABLE {0} ", UsersMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("TRUNCATE TABLE {0} ", ImageMeta.TableName), null);
			}

			if (mgr.DbAccessType == DbAccessType.SqLite)
			{
				mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", UsersMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("VACUUM"), null);
				mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", BookMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("VACUUM"), null);
				mgr.ExecuteGenericCommand(string.Format("DELETE FROM {0} ", ImageMeta.TableName), null);
				mgr.ExecuteGenericCommand(string.Format("VACUUM"), null);
			}
		}