public void EmptyQuery()
        {
            var       db = new Energy.Source.Connection();
            string    error;
            object    result;
            int       number;
            DataTable table;

            Energy.Base.Table fetch;
            result = db.Scalar(null, out error);
            Assert.AreEqual("Empty query", error);
            Assert.IsNull(result);
            result = db.Scalar("", out error);
            Assert.AreEqual("Empty query", error);
            Assert.IsNull(result);
            number = db.Scalar <int>(null, out error);
            Assert.AreEqual("Empty query", error);
            Assert.AreEqual(0, number);
            number = db.Execute(null, out error);
            Assert.AreEqual("Empty query", error);
            Assert.AreEqual(-2, number);
            table = db.Read(null, out error);
            Assert.AreEqual("Empty query", error);
            Assert.IsNull(table);
            fetch = db.Fetch(null, out error);
            Assert.AreEqual("Empty query", error);
            Assert.IsNull(fetch);
            table = db.Load(null, out error);
            Assert.AreEqual("Empty query", error);
            Assert.IsNull(table);
        }
Beispiel #2
0
        internal static void GetDate()
        {
            string connStr = "Data Source=.\\SQLEXPRESS;Initial Catalog=master;Integrated Security=Yes;Connect Timeout=10;";

            connStr = Energy.Core.Tilde.Ask("Connection string", connStr);
            Energy.Source.Connection <SqlConnection> source = new Energy.Source.Connection <SqlConnection>(connectionString: connStr);
            source.Persistent = false;
            int num1 = Energy.Core.Benchmark.Loop(() => { string result = source.Scalar <string>("SELECT GETDATE()"); }, 1);

            source.Persistent = true;
            int num2 = Energy.Core.Benchmark.Loop(() => { string result = source.Scalar <string>("SELECT GETDATE()"); }, 1);

            Console.WriteLine($"Dynamic {num1} Persistent {num2}");
        }
Beispiel #3
0
        private static void Go(string[] args)
        {
            string connectionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=platoon;Integrated Security=Yes;Connect Timeout=10;";

            connectionString = @"Data Source=10.0.2.2;Initial Catalog=platoon;Integrated Security=No;User Id=platoon;Password=platoon;Connect Timeout=10;";
            //connectionString = @"Data Source=W101-SQL01;Initial Catalog=BisSQL;Integrated Security=False;User ID=bissqluser;Password=B1sSqLP@ssW0rd;MultipleActiveResultSets=True;Connect Timeout=10";
            //connectionString = @"Data Source=W103-FS02;Initial Catalog=BisSQLTest;Integrated Security=False;User ID=SZCbistestuser;Password=f4c!S7CzeCInSQLT3st!;MultipleActiveResultSets=True;Connect Timeout=30";
            db = new Energy.Source.Connection <SqlConnection>(connectionString);

            Console.WriteLine(db.Scalar("SELECT GETDATE()"));

            Test1();
            Test2();
        }
Beispiel #4
0
        public static void Work(object parameter)
        {
            Tuple <int, Energy.Source.Connection> data = (Tuple <int, Energy.Source.Connection>)parameter;
            int number = data.Item1;

            Energy.Source.Connection connection = data.Item2;
            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine("Thread:Iteration {0}:{1} {2}"
                                  , number + 1
                                  , i + 1
                                  , connection.Scalar <string>("DO SLEEP(1); SELECT CURRENT_TIMESTAMP()")
                                  );
            }
        }
Beispiel #5
0
        private static void Test1(string[] args)
        {
            string connectionString = @"Data Source=:memory:;Version=3;New=True;";

            db            = new Energy.Source.Connection <System.Data.SQLite.SQLiteConnection>(connectionString);
            db.Persistent = true; // needed for :memory: !!!
            Console.WriteLine(db.Scalar("select current_timestamp;"));
            Console.WriteLine(db.Scalar("select time(time(), 'localtime');"));
            Console.WriteLine(db.Scalar("SELECT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW'))"));
            Energy.Interface.IDialect dialect = new Energy.Query.Dialect.SQLITE();
            Energy.Interface.IDialect script  = new Energy.Query.Dialect.SQLITE();
            string query;

            query = "select " + dialect.Format.CurrentStamp;
            Console.WriteLine(query);
            Console.WriteLine(db.Scalar(query));

            Energy.Source.Structure.Table table;
            table = Energy.Source.Structure.Table.Create(typeof(UserTableRecord));
            query = dialect.CreateTable(table);

            Console.WriteLine(query);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }

            query = "INSERT INTO " + script.Format.Object("UserTable") + " ( Name , Phone ) VALUES ( 'List' , 1234 )";

            Console.WriteLine(query);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }

            query = "INSERT INTO " + script.Format.Object("UserTable") + " ( Name , Phone ) VALUES ( 'Element numer 1' , 4143141414 )";

            Console.WriteLine(query);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }

            query = "INSERT INTO " + script.Format.Object("UserTable") + " ( Name ) VALUES ( 'Po prostu element' )";

            Console.WriteLine(query);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }

            query = "INSERT INTO " + script.Format.Object("UserTable") + " ( Name , Description ) VALUES ( '===' , 'ĄćęłńóśćżŹ' )";

            Console.WriteLine(query);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }

            query = "SELECT * FROM " + script.Format.Object("UserTable");

            Console.WriteLine(query);
            DataTable dx1  = db.Load(query);
            string    text = Energy.Base.Plain.DataTableToPlainText(dx1, new Energy.Base.Plain.TableFormat.FullFrame()
            {
                Tilde = true
            });

            Energy.Core.Tilde.WriteLine(text);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }

            var tbl = db.Fetch(query);

            foreach (var rec in tbl)
            {
                Console.WriteLine(rec.ToString(": "));
            }

            Console.WriteLine(query);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            Energy.Core.Tilde.WriteLine("~y~MySQL ~w~connection example");

            Energy.Core.Log.Default.Destination.Add(new Energy.Core.Log.Target.Console());

            Energy.Source.Connection <MySql.Data.MySqlClient.MySqlConnection> db;
            db = new Energy.Source.Connection <MySql.Data.MySqlClient.MySqlConnection>();
            db.ConnectionString = @"Server=127.0.0.1;Database=test;Uid=test;Pwd=test;";

            db.OnCreate += Db_OnCreate;
            db.OnClose  += Db_OnClose;

            string query = "SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST";

            //Console.WriteLine(db.Read))
            Console.WriteLine(db.Fetch(query).ToPlain());

            Energy.Core.Tilde.WriteLine("~c~Using 3 threads to retreive current timestamp 3 times with delay of 1 second each");
            Energy.Core.Tilde.WriteLine("~y~Starting in persistent mode (one connection only)");

            db.Persistent = true;

            for (int i = 0; i < 3; i++)
            {
                Thread thread = new Thread(Work);
                thread.Start(new Tuple <int, Energy.Source.Connection>(i, db));
            }

            Energy.Core.Tilde.Pause();

            Energy.Core.Tilde.WriteLine("~y~Now in not persistent mode (opening new connection per each statement)");

            db.Persistent = false;

            for (int i = 0; i < 3; i++)
            {
                Thread thread = new Thread(Work);
                thread.Start(new Tuple <int, Energy.Source.Connection>(i, db));
            }

            Energy.Core.Tilde.Pause();

            db.ConnectionString = @"Server=127.0.0.1;Database=platoon;Uid=platoon;Pwd=platoon;";
            db.Open();
            Console.WriteLine(db.Scalar("SELECT CURRENT_TIMESTAMP()"));

            Energy.Source.Structure.Table table  = Energy.Source.Structure.Table.Create(typeof(UserTableRecord));
            Energy.Interface.IDialect     script = new Energy.Query.Dialect.MYSQL();

            query = script.CreateDescription(table);
            Console.WriteLine(query);

            query = script.DropTable(table.Name);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }
            Console.WriteLine(query);
            query = script.CreateTable(table);
            if (db.Execute(query) < 0)
            {
                Console.WriteLine(db.ErrorMessage);
            }
            Console.WriteLine(query);

            Console.ReadLine();
        }