Exemplo n.º 1
0
        private static void DoDemo(EDBConnection connection)
        {
            Console.Write("Inserting row 1... ");
            using (var cmd = new EdbAffectedRowsCommand("INSERT INTO demo (value_unicode) VALUES (:param)", connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(
                    new EDBParameter("param", "Lithuanian chars: ĖĮĘĮŲŠŲŪŠŲčęėūįčųū, russian chars: ваниа маша"));

                // Bit overprotective probably, but using 3rd party libs its usual to be overprotective
                if (cmd.Execute() != 1)
                {
                    throw new InvalidOperationException();
                }
                //

                Console.WriteLine("DONE");
            }

            Console.Write("Inserting row 2... ");
            using (
                var cmd = new EdbAffectedRowsCommand(
                    "INSERT INTO demo (value_unicode, value_decimal) VALUES (:param1, :param2)",
                    connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(new EDBParameter("param1", DBNull.Value));
                cmd.Parameters.Add(
                    new EDBParameter(
                        "param2",
                        3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679m));

                // Bit overprotective probably, but using 3rd party libs its usual to be overprotective
                if (cmd.Execute() != 1)
                {
                    throw new InvalidOperationException();
                }
                //

                Console.WriteLine("DONE");
            }

            Console.Write("Inserting row 3, and get its id... ");
            using (
                var cmd =
                    new EdbAffectedRowsCommand(
                        "INSERT INTO demo (value_unicode, value_decimal, value_datetime, value_bool) VALUES (:param1, :param2, :param3, :param4)",
                        connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(new EDBParameter("param1", DBNull.Value));
                cmd.Parameters.Add(new EDBParameter("param2", DBNull.Value));
                cmd.Parameters.Add(new EDBParameter("param3", DateTime.UtcNow));
                cmd.Parameters.Add(new EDBParameter("param4", true));

                // Bit overprotective probably, but using 3rd party libs its usual to be overprotective
                if (cmd.Execute() != 1)
                {
                    throw new InvalidOperationException();
                }
                //

                using (var cmd2 = new EdbScalarCommand <int>("SELECT LASTIDENTITY('demo', 'id')", connection))
                {
                    Console.WriteLine("DONE, with id - {0}", cmd2.Execute());
                }
            }

            Console.Write("Getting two rows... ");
            using (var cmd = new EdbDataTableCommand("SELECT * FROM demo RANGE 2 TO 3", connection))
            {
                var dt = cmd.Execute();
                Console.WriteLine("DONE");

                foreach (DataRow row in dt.Rows)
                {
                    Console.WriteLine(
                        "Got row with id: {0}, timestamp: {1}, values: {2},{3},{4}",
                        row["id"],
                        row["value_datetime"],
                        row["value_unicode"],
                        row["value_decimal"],
                        row["value_bool"]);
                }
            }

            Console.Write("Updating timestamps where null... ");
            using (
                var cmd = new EdbAffectedRowsCommand(
                    "UPDATE demo SET value_datetime = :param WHERE value_datetime IS NULL",
                    connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(new EDBParameter("param", DateTime.MinValue));
                var cnt = cmd.Execute();
                Console.WriteLine("DONE, {0} rows updated", cnt);
            }

            Console.Write("Getting all rows... ");
            using (var cmd = new EdbDataTableCommand("SELECT * FROM demo", connection))
            {
                var dt = cmd.Execute();
                Console.WriteLine("DONE");

                foreach (DataRow row in dt.Rows)
                {
                    Console.WriteLine(
                        "Got row with id: {0}, timestamp: {1}, values: {2},{3},{4}",
                        row["id"],
                        row["value_datetime"],
                        row["value_unicode"],
                        row["value_decimal"],
                        row["value_bool"]);
                }
            }
        }
Exemplo n.º 2
0
        private static void DoDemo(EDBConnection connection)
        {
            Console.Write("Inserting row 1... ");
            using (var cmd = new EdbAffectedRowsCommand("INSERT INTO demo (value_unicode) VALUES (:param)", connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(
                    new EDBParameter("param", "Lithuanian chars: ĖĮĘĮŲŠŲŪŠŲčęėūįčųū, russian chars: ваниа маша"));

                // Bit overprotective probably, but using 3rd party libs its usual to be overprotective
                if (cmd.Execute() != 1)
                    throw new InvalidOperationException();
                //

                Console.WriteLine("DONE");
            }

            Console.Write("Inserting row 2... ");
            using (
                var cmd = new EdbAffectedRowsCommand(
                    "INSERT INTO demo (value_unicode, value_decimal) VALUES (:param1, :param2)",
                    connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(new EDBParameter("param1", DBNull.Value));
                cmd.Parameters.Add(
                    new EDBParameter(
                        "param2",
                        3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679m));

                // Bit overprotective probably, but using 3rd party libs its usual to be overprotective
                if (cmd.Execute() != 1)
                    throw new InvalidOperationException();
                //
                
                Console.WriteLine("DONE");
            }

            Console.Write("Inserting row 3, and get its id... ");
            using (
                var cmd =
                    new EdbAffectedRowsCommand(
                        "INSERT INTO demo (value_unicode, value_decimal, value_datetime, value_bool) VALUES (:param1, :param2, :param3, :param4)",
                        connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(new EDBParameter("param1", DBNull.Value));
                cmd.Parameters.Add(new EDBParameter("param2", DBNull.Value));
                cmd.Parameters.Add(new EDBParameter("param3", DateTime.UtcNow));
                cmd.Parameters.Add(new EDBParameter("param4", true));

                // Bit overprotective probably, but using 3rd party libs its usual to be overprotective
                if (cmd.Execute() != 1)
                    throw new InvalidOperationException();
                //

                using (var cmd2 = new EdbScalarCommand<int>("SELECT LASTIDENTITY('demo', 'id')", connection))
                {
                    Console.WriteLine("DONE, with id - {0}", cmd2.Execute());
                }
            }

            Console.Write("Getting two rows... ");
            using (var cmd = new EdbDataTableCommand("SELECT * FROM demo RANGE 2 TO 3", connection))
            {
                var dt = cmd.Execute();
                Console.WriteLine("DONE");

                foreach (DataRow row in dt.Rows)
                {
                    Console.WriteLine(
                        "Got row with id: {0}, timestamp: {1}, values: {2},{3},{4}",
                        row["id"],
                        row["value_datetime"],
                        row["value_unicode"],
                        row["value_decimal"],
                        row["value_bool"]);
                }
            }

            Console.Write("Updating timestamps where null... ");
            using (
                var cmd = new EdbAffectedRowsCommand(
                    "UPDATE demo SET value_datetime = :param WHERE value_datetime IS NULL",
                    connection))
            {
                cmd.Prepare();
                cmd.Parameters.Add(new EDBParameter("param", DateTime.MinValue));
                var cnt = cmd.Execute();
                Console.WriteLine("DONE, {0} rows updated", cnt);
            }

            Console.Write("Getting all rows... ");
            using (var cmd = new EdbDataTableCommand("SELECT * FROM demo", connection))
            {
                var dt = cmd.Execute();
                Console.WriteLine("DONE");

                foreach (DataRow row in dt.Rows)
                {
                    Console.WriteLine(
                        "Got row with id: {0}, timestamp: {1}, values: {2},{3},{4}",
                        row["id"],
                        row["value_datetime"],
                        row["value_unicode"],
                        row["value_decimal"],
                        row["value_bool"]);
                }
            }
        }