Exemplo n.º 1
0
        private static EDBConnection CreateDemoConnectionInteractive(string db, bool doLocal)
        {
            var connectionString = new EDBConnectionStringBuilder
            {
                Database     = "Configuration",
                CharSet      = "UNICODE",
                ConfigMemory = false
            };

            if (doLocal)
            {
                connectionString.Type = "LOCAL";

                Console.Write("Local DB folder (Hit <Enter> to switch to inmemory): ");
                var localDbFolder = Console.ReadLine();
                connectionString.ConfigMemory = false;
                if (!string.IsNullOrEmpty(localDbFolder))
                {
                    connectionString.ConfigPath = localDbFolder;
                }
                else
                {
                    connectionString.ConfigMemory = true;
                }
            }
            else
            {
                connectionString.Type = "REMOTE";

                Console.Write("Host (Hit <Enter> to switch to localhost): ");
                var host = Console.ReadLine();
                connectionString.Host = string.IsNullOrEmpty(host) ? "localhost" : host;

                Console.Write("Port (Hit <Enter> to switch to 12010): ");
                var port = Console.ReadLine();
                connectionString.Port = string.IsNullOrEmpty(port) ? 12010 : int.Parse(port);
            }

            Console.Write("Username (Hit <Enter> to Administrator): ");
            var userName = Console.ReadLine();

            connectionString.UID = string.IsNullOrEmpty(userName) ? "Administrator" : userName;

            Console.Write("Password (Hit <Enter> to EDBDefault): ");
            var password = Console.ReadLine();

            connectionString.PWD = string.IsNullOrEmpty(password) ? "EDBDefault" : password;

            Console.Write("Initiating connection... ");
            using (var connection = new EDBConnection(connectionString.ToString()))
            {
                connection.Open();
                Console.WriteLine("SUCCESS");

                Console.Write("Opening database... ");
                connectionString.Database = db;
                using (var connection2 = new EDBConnection(connectionString.ToString()))
                {
                    try
                    {
                        connection2.Open();
                        Console.WriteLine("SUCCESS");
                    }
                    catch (Exception)
                    {
                        Console.Write("FAILED... Creating inmemory database for demo purposes... ");
                        using (
                            var cmd =
                                new EDBCommand(
                                    string.Format("CREATE DATABASE \"{0}\" IN MEMORY", db.Replace("\"", "\"\"")),
                                    // DDL escaping, no standard way to do this
                                    connection))
                        {
                            cmd.ExecuteNonQuery();
                            Console.WriteLine("SUCCESS");
                        }
                    }

                    Console.Write("Opening database... ");
                    connection2.Open();
                    Console.WriteLine("SUCCESS");

                    Console.Write("Creating demo table... ");
                    using (
                        var cmd =
                            new EDBCommand(
                                "DROP TABLE \"demo\"",
                                connection2))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch // Let delete fail, it may be ok
                        {
                        }
                    }

                    using (
                        var cmd =
                            new EDBCommand(
                                @"
CREATE TABLE ""demo""
(
id INT GENERATED BY DEFAULT AS IDENTITY
(START WITH 0, INCREMENT BY 1) PRIMARY KEY,
value_unicode VARCHAR(255) COLLATE ""UNI"",
value_decimal DECIMAL(14,4), -- 4 is macimum scale!!! WTF?
value_dateTime TIMESTAMP,
value_bool BOOL
)",
                                connection2))
                    {
                        cmd.ExecuteNonQuery();
                        Console.WriteLine("SUCCESS");

                        return(new EDBConnection(connectionString.ToString()));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static EDBConnection CreateDemoConnectionInteractive(string db, bool doLocal)
        {
            var connectionString = new EDBConnectionStringBuilder
            {
                Database = "Configuration",
                CharSet = "UNICODE",
                ConfigMemory = false
            };

            if (doLocal)
            {
                connectionString.Type = "LOCAL";

                Console.Write("Local DB folder (Hit <Enter> to switch to inmemory): ");
                var localDbFolder = Console.ReadLine();
                connectionString.ConfigMemory = false;
                if (!string.IsNullOrEmpty(localDbFolder))
                {
                    connectionString.ConfigPath = localDbFolder;
                }
                else
                {
                    connectionString.ConfigMemory = true;
                }
            }
            else
            {
                connectionString.Type = "REMOTE";

                Console.Write("Host (Hit <Enter> to switch to localhost): ");
                var host = Console.ReadLine();
                connectionString.Host = string.IsNullOrEmpty(host) ? "localhost" : host;

                Console.Write("Port (Hit <Enter> to switch to 12010): ");
                var port = Console.ReadLine();
                connectionString.Port = string.IsNullOrEmpty(port) ? 12010 : int.Parse(port);
            }

            Console.Write("Username (Hit <Enter> to Administrator): ");
            var userName = Console.ReadLine();
            connectionString.UID = string.IsNullOrEmpty(userName) ? "Administrator" : userName;

            Console.Write("Password (Hit <Enter> to EDBDefault): ");
            var password = Console.ReadLine();
            connectionString.PWD = string.IsNullOrEmpty(password) ? "EDBDefault" : password;

            Console.Write("Initiating connection... ");
            using (var connection = new EDBConnection(connectionString.ToString()))
            {
                connection.Open();
                Console.WriteLine("SUCCESS");

                Console.Write("Opening database... ");
                connectionString.Database = db;
                using (var connection2 = new EDBConnection(connectionString.ToString()))
                {
                    try
                    {
                        connection2.Open();
                        Console.WriteLine("SUCCESS");
                    }
                    catch (Exception)
                    {
                        Console.Write("FAILED... Creating inmemory database for demo purposes... ");
                        using (
                            var cmd =
                                new EDBCommand(
                                    string.Format("CREATE DATABASE \"{0}\" IN MEMORY", db.Replace("\"", "\"\"")),
                                    // DDL escaping, no standard way to do this
                                    connection))
                        {
                            cmd.ExecuteNonQuery();
                            Console.WriteLine("SUCCESS");
                        }
                    }

                    Console.Write("Opening database... ");
                    connection2.Open();
                    Console.WriteLine("SUCCESS");

                    Console.Write("Creating demo table... ");
                    using (
                        var cmd =
                            new EDBCommand(
                                "DROP TABLE \"demo\"",
                                connection2))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch // Let delete fail, it may be ok
                        {
                        }
                    }

                    using (
                        var cmd =
                            new EDBCommand(
                                @"
CREATE TABLE ""demo""
(
id INT GENERATED BY DEFAULT AS IDENTITY
(START WITH 0, INCREMENT BY 1) PRIMARY KEY,
value_unicode VARCHAR(255) COLLATE ""UNI"",
value_decimal DECIMAL(14,4), -- 4 is macimum scale!!! WTF?
value_dateTime TIMESTAMP,
value_bool BOOL
)",
                                connection2))
                    {
                        cmd.ExecuteNonQuery();
                        Console.WriteLine("SUCCESS");

                        return new EDBConnection(connectionString.ToString());
                    }
                }
            }
        }