Пример #1
0
		static bool SQLITE()
		{
			try
			{
				// LoadAll
				CSharp.SQLite.vwEmployees vemps = new CSharp.SQLite.vwEmployees();
				vemps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
				vemps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.EmployeeID);
				vemps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.LastName);
				vemps.Query.AddOrderBy(CSharp.SQLite.Employees.ColumnNames.LastName, WhereParameter.Dir.ASC);
				vemps.Query.Top = 2;
				if(!vemps.Query.Load())
				{
					return false; // ERROR
				}

				// LoadAll
				CSharp.SQLite.Employees emps = new CSharp.SQLite.Employees();
				emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
				emps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.EmployeeID);
				emps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.LastName);
				emps.Query.AddOrderBy(CSharp.SQLite.Employees.ColumnNames.LastName, WhereParameter.Dir.ASC);
				emps.Query.Top = 2;
				if(!emps.Query.Load())
				{
					return false; // ERROR
				}

				// LoadAll
				emps = new CSharp.SQLite.Employees();
				emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
				if(!emps.LoadAll())
				{
					return false; // ERROR
				}

				// LoadByPrimaryKey
				long id = emps.EmployeeID;
				emps = new CSharp.SQLite.Employees();
				emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
				if(!emps.LoadByPrimaryKey(id))
				{
					return false; // ERROR
				}

				// AddNew/Save
				emps = new CSharp.SQLite.Employees();
				emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
				emps.AddNew();
				emps.FirstName = "trella1";
				emps.LastName  = "trella1";
				emps.AddNew();
				emps.FirstName = "trella2";
				emps.LastName  = "trella2";
				emps.Save();

				// Query.Load/Update/Save
				emps = new CSharp.SQLite.Employees();
				emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
				emps.Where.FirstName.Value = "trella%";
				emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
				emps.Where.LastName.Value = "trella%";
				emps.Where.LastName.Operator = WhereParameter.Operand.Like;
				if(!emps.Query.Load())
				{
					return false; // ERROR
				}

				do
					emps.LastName = emps.LastName + ":new";
				while(emps.MoveNext());

				emps.Save();

				// Transaction
				CSharp.SQLite.Employees emps1 = new CSharp.SQLite.Employees();
				emps1.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
				emps1.AddNew();
				emps1.FirstName = "trella1_tx1";
				emps1.LastName  = "trella1_tx1";

				CSharp.SQLite.Employees emps2 = new CSharp.SQLite.Employees();
				emps2.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
				emps2.AddNew();
				emps2.FirstName = "trella1_tx2";
				emps2.LastName  = "trella1_tx2";

				TransactionMgr.ThreadTransactionMgr().BeginTransaction();
				emps1.Save();
				emps2.Save();
				TransactionMgr.ThreadTransactionMgr().CommitTransaction();

				// Query.Load/MarkAsDeleted/Save
				emps = new CSharp.SQLite.Employees();
				emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
				emps.Where.FirstName.Value = "trella%";
				emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
				emps.Where.LastName.Value = "trella%";
				emps.Where.LastName.Operator = WhereParameter.Operand.Like;
				if(!emps.Query.Load())
				{
					return false; // ERROR
				}

				emps.DeleteAll();
				emps.Save();
			}
			catch(Exception ex)
			{
				Console.WriteLine(ex.Message);
				return false;
			}
			finally
			{
				TransactionMgr.ThreadTransactionMgrReset();
			}

			return true;
		}
Пример #2
0
        static bool SQLITE()
        {
            try
            {
                // LoadAll
                CSharp.SQLite.vwEmployees vemps = new CSharp.SQLite.vwEmployees();
                vemps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                vemps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.EmployeeID);
                vemps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.LastName);
                vemps.Query.AddOrderBy(CSharp.SQLite.Employees.ColumnNames.LastName, WhereParameter.Dir.ASC);
                vemps.Query.Top = 2;
                if (!vemps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                // LoadAll
                CSharp.SQLite.Employees emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                emps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.EmployeeID);
                emps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.LastName);
                emps.Query.AddOrderBy(CSharp.SQLite.Employees.ColumnNames.LastName, WhereParameter.Dir.ASC);
                emps.Query.Top = 2;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                // LoadAll
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                long id = emps.EmployeeID;
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString         = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.SQLite.Employees emps1 = new CSharp.SQLite.Employees();
                emps1.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.SQLite.Employees emps2 = new CSharp.SQLite.Employees();
                emps2.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString         = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }