internal void UpdateStaff(int id, Staff staff)
        {
            using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    string commandText =
                        @"UPDATE staff
SET fName=@FNAME, lName=@LNAME, username=@USERNAME, password=@PASSWORD, email=@EMAIL, accessLevel=@ACCESSLEVEL
WHERE staffId=@STAFFID";
                    MySqlCommand command = new MySqlCommand(commandText, conn);
                    command.Parameters.Add("@FNAME", MySqlDbType.VarChar);;
                    command.Parameters["@FNAME"].Value = staff.fName;
                    command.Parameters.Add("@LNAME", MySqlDbType.VarChar);
                    command.Parameters["@LNAME"].Value = staff.lName;
                    command.Parameters.Add("@USERNAME", MySqlDbType.VarChar);
                    command.Parameters["@USERNAME"].Value = staff.username;
                    command.Parameters.Add("@PASSWORD", MySqlDbType.VarChar);
                    command.Parameters["@PASSWORD"].Value = staff.password;
                    command.Parameters.Add("@EMAIL", MySqlDbType.VarChar);
                    command.Parameters["@EMAIL"].Value = staff.email;
                    command.Parameters.Add("@ACCESSLEVEL", MySqlDbType.Int32);
                    command.Parameters["@ACCESSLEVEL"].Value = staff.accessLevel;
                    command.Parameters.Add("@STAFFID", MySqlDbType.Int32);
                    command.Parameters["@STAFFID"].Value = id;
                    command.ExecuteNonQuery();
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
        }
        internal List <Check> GetAll()
        {
            var checks = new List <Check>();

            using (MySqlConnection conn = new MySqlConnection(_connectionString))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    using (MySqlCommand command = new MySqlCommand("SELECT * FROM checkDB.`chekue`", conn))
                    {
                        MySqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            checks.Add(new Check()
                            {
                                IdCheck   = reader.GetInt32("idCheck"),
                                IdAccount = reader.GetInt32("idAccount"),
                                IdStore   = reader.GetInt32("idStore"),
                                CheckNum  = reader.GetInt32("checkNum"),
                                Amount    = reader.GetFloat("amount"),
                                //DateWritten = reader.GetDateTime("dateWritten"),
                                //AmountPaid = (!reader.IsDBNull(reader.GetOrdinal("amountPaid"))) ? reader.GetFloat("amountPaid") : -1,
                                //PaidDate = (!reader.IsDBNull(reader.GetOrdinal("paidDate"))) ? reader.GetDateTime("paidDate") : new DateTime(0)
                            });
                        }
                    }
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }

            return(checks);
        }
        // RETURNS: One check that matches the given <id>
        internal Check GetCheck(int id)
        {
            var check = new Check();

            using (MySqlConnection conn = new MySqlConnection(_connectionString))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    using (MySqlCommand command = new MySqlCommand("SELECT * FROM checkDB.`chekue` AS checks WHERE checks.idCheck = " + Convert.ToString(id), conn))
                    {
                        MySqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            check = new Check()
                            {
                                IdCheck     = reader.GetInt32("idCheck"),
                                IdAccount   = reader.GetInt32("idAccount"),
                                IdStore     = reader.GetInt32("idStore"),
                                CheckNum    = reader.GetInt32("checkNum"),
                                Amount      = reader.GetFloat("amount"),
                                DateWritten = reader.GetDateTime("dateWritten"),
                                AmountPaid  = (!reader.IsDBNull(reader.GetOrdinal("amountPaid"))) ? reader.GetFloat("amountPaid") : -1,
                                PaidDate    = (!reader.IsDBNull(reader.GetOrdinal("paidDate"))) ? reader.GetDateTime("paidDate") : new DateTime(0)
                            };
                        }
                    }
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
            return(check);
        }
        internal void CreateStaff(Staff staff)
        {
            using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    string commandText =
                        @"INSERT INTO staff (fName, lName, username, password, email, accessLevel, creationDate)
VALUES(@FNAME, @LNAME, @USERNAME, @PASSWORD, @EMAIL, @ACCESSLEVEL, @CREATIONDATE)";
                    MySqlCommand command = new MySqlCommand(commandText, conn);
                    command.Parameters.Add("@FNAME", MySqlDbType.VarChar);;
                    command.Parameters["@FNAME"].Value = staff.fName;
                    command.Parameters.Add("@LNAME", MySqlDbType.VarChar);
                    command.Parameters["@LNAME"].Value = staff.lName;
                    command.Parameters.Add("@USERNAME", MySqlDbType.VarChar);
                    command.Parameters["@USERNAME"].Value = staff.username;
                    command.Parameters.Add("@PASSWORD", MySqlDbType.VarChar);
                    command.Parameters["@PASSWORD"].Value = staff.password;
                    command.Parameters.Add("@EMAIL", MySqlDbType.VarChar);
                    command.Parameters["@EMAIL"].Value = staff.email;
                    command.Parameters.Add("@ACCESSLEVEL", MySqlDbType.Int32);
                    command.Parameters["@ACCESSLEVEL"].Value = staff.accessLevel;
                    command.Parameters.Add("@CREATIONDATE", MySqlDbType.DateTime);
                    command.Parameters["@CREATIONDATE"].Value = staff.creationDate;
                    command.ExecuteNonQuery();
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
        }
        internal IEnumerable <CheckDisplayRow> RetrieveAllCheckDisplayRows()
        {
            List <CheckDisplayRow> rows = new List <CheckDisplayRow>();
            CheckDisplayRow        row  = null;

            using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    using (MySqlCommand command = new MySqlCommand("SELECT * FROM checkdb.checkdisplayrow", conn))
                    {
                        MySqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            row = new CheckDisplayRow()
                            {
                                idCheck     = reader.GetInt32("idCheck"),
                                idAccount   = reader.GetInt32("idAccount"),
                                idStore     = reader.GetInt32("idStore"),
                                checkNum    = reader.GetInt32("checkNum"),
                                amount      = reader.GetFloat("amount"),
                                dateWritten = reader.GetDateTime("dateWritten"),
                                //amountPaid = reader.GetFloat("amountPaid"),//nullable
                                //paidDate = reader.GetDateTime("paidDate"),//nullable
                                amountPaid = (!reader.IsDBNull(reader.GetOrdinal("amountPaid"))) ? reader.GetFloat("amountPaid") : -1,
                                paidDate   = (!reader.IsDBNull(reader.GetOrdinal("paidDate"))) ? reader.GetDateTime("paidDate") : new DateTime(0),
                                routingNum = reader.GetInt32("routingNum"),
                                accountNum = reader.GetInt32("accountNum"),
                                fName      = reader.GetString("fName"),
                                lName      = reader.GetString("lName"),
                                //fName2 = reader.GetString("fName2"),//nullable
                                //lName2 = reader.GetString("lName2"),//
                                fName2  = (!reader.IsDBNull(reader.GetOrdinal("fName2"))) ? reader.GetString("fName2") : "",
                                lName2  = (!reader.IsDBNull(reader.GetOrdinal("lName2"))) ? reader.GetString("lName2") : "",
                                address = reader.GetString("address"),
                                city    = reader.GetString("city"),
                                state   = reader.GetString("state"),
                                zipcode = reader.GetInt32("zipcode"),
                                //phoneNum = reader.GetString("phoneNum"),//nullable
                                phoneNum     = (!reader.IsDBNull(reader.GetOrdinal("phoneNum"))) ? reader.GetString("phoneNum") : "",
                                bName        = reader.GetString("bName"),
                                bAddress     = reader.GetString("bAddress"),
                                bCity        = reader.GetString("bCity"),
                                bState       = reader.GetString("bState"),
                                bZipcode     = reader.GetInt32("bZipcode"),
                                idStoreGroup = reader.GetInt32("idStoreGroup"),
                                sName        = reader.GetString("sName"),
                                sAddress     = reader.GetString("sAddress"),
                                sCity        = reader.GetString("sCity"),
                                sState       = reader.GetString("sState"),
                                sZipcode     = reader.GetInt32("sZipcode")
                            };
                            rows.Add(row);
                        }
                    }
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
            return(rows);
        }
Example #6
0
        public static void RecreateMySqlDatabase(string section)
        {
            var connManagerMaster = new MySqlConnectionManager(
                Config.MySqlConnection.ConnectionString(section).CloneWithMasterDbName()
                );
            var dbName = Config.MySqlConnection.ConnectionString(section).DbName;

            DropAndCreate(connManagerMaster, dbName);
        }
        public void CanParseSingleLineScript()
        {
            const string singleCommand = "CREATE TABLE IF NOT EXISTS 'FOO';";

            var connectionManager = new MySqlConnectionManager("connectionstring");
            var result            = connectionManager.SplitScriptIntoCommands(singleCommand);

            result.Count().ShouldBe(1);
        }
        internal void UpdateCheckDisplayRow(int id, CheckDisplayRow row)
        {
            using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    string commandText =
                        @"UPDATE chekue
SET idAccount=@IDACCOUNT, idStore=@IDSTORE, checkNum=@CHECKNUM, amount=@AMOUNT, dateWritten=@DATEWRITTEN{AMOUNTPAID}{PAIDDATE}
WHERE idCheck=@IDCHECK";
                    if (row.amountPaid != -1)
                    {
                        commandText = commandText.Replace("{AMOUNTPAID}", ", amountPaid=@AMOUNTPAID");
                    }
                    else
                    {
                        commandText = commandText.Replace("{AMOUNTPAID}", "");
                    }
                    if (row.paidDate != null && row.paidDate != new DateTime(0))
                    {
                        commandText = commandText.Replace("{PAIDDATE}", ", paidDate=@PAIDDATE");
                    }
                    else
                    {
                        commandText = commandText.Replace("{PAIDDATE}", "");
                    }
                    MySqlCommand command = new MySqlCommand(commandText, conn);
                    //add and set all the parameters here.  Some hefty crying must first occur before I implement this....
                    if (row.amountPaid != -1)
                    {
                        command.Parameters.Add("@AMOUNTPAID", MySqlDbType.Float);
                        command.Parameters["@AMOUNTPAID"].Value = row.amountPaid;
                    }
                    if (row.paidDate != null && row.paidDate != new DateTime(0))
                    {
                        command.Parameters.Add("@PAIDDATE", MySqlDbType.DateTime);
                        command.Parameters["@PAIDDATE"].Value = row.paidDate;
                    }
                    command.Parameters.Add("@IDACCOUNT", MySqlDbType.Int32);
                    command.Parameters["@IDACCOUNT"].Value = row.idAccount;
                    command.Parameters.Add("@IDSTORE", MySqlDbType.Int32);
                    command.Parameters["@IDSTORE"].Value = row.idStore;
                    command.Parameters.Add("@CHECKNUM", MySqlDbType.Int32);
                    command.Parameters["@CHECKNUM"].Value = row.checkNum;
                    command.Parameters.Add("@AMOUNT", MySqlDbType.Float);
                    command.Parameters["@AMOUNT"].Value = row.amount;
                    command.Parameters.Add("@DATEWRITTEN", MySqlDbType.DateTime);
                    command.Parameters["@DATEWRITTEN"].Value = row.dateWritten;
                    command.Parameters.Add("@IDCHECK", MySqlDbType.Int32);
                    command.Parameters["@IDCHECK"].Value = id;
                    command.ExecuteNonQuery();
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Opens a connection to a mysql server.
        /// </summary>
        public bool real_connect(Context ctx, string host = null, string username = null, string passwd = null, string dbname = "", int port = -1, string socket = null, int flags = 0)
        {
            var config            = ctx.Configuration.Get <MySqlConfiguration>();
            int connectiontimeout = 0;

            if (_lazyoptions != null)
            {
                PhpValue value;
                if (_lazyoptions.TryGetValue(Constants.MYSQLI_OPT_CONNECT_TIMEOUT, out value))
                {
                    connectiontimeout = (int)value.ToLong();
                }
            }

            // string $host = ini_get("mysqli.default_host")
            // string $username = ini_get("mysqli.default_user")
            // string $passwd = ini_get("mysqli.default_pw")
            // string $dbname = ""
            // int $port = ini_get("mysqli.default_port")
            // string $socket = ini_get("mysqli.default_socket")

            // p:
            if (host != null && host.StartsWith("p:", StringComparison.Ordinal))
            {
                host   = host.Substring(2);
                flags |= (int)MySql.ConnectFlags.Pooling;
            }

            //
            var connection_string = MySql.BuildConnectionString(config, ref host, port, username, passwd,
                                                                flags: (MySql.ConnectFlags)flags,
                                                                connectiontimeout: connectiontimeout);

            _connection = MySqlConnectionManager.GetInstance(ctx)
                          .CreateConnection(connection_string, false, -1, out bool success);

            if (success)
            {
                _connection.Server = host;

                if (!string.IsNullOrEmpty(dbname))
                {
                    _connection.SelectDb(dbname);
                }
            }
            else
            {
                MySqliContextData.GetContextData(ctx).LastConnectionError
                      = connect_error
                      = _connection.GetLastErrorMessage();
            }

            //
            return(success);
        }
        public void CanParseMultilineScript()
        {
            var multiCommand = "CREATE TABLE IF NOT EXISTS 'FOO';";

            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE IF NOT EXISTS 'BAR';";

            var connectionManager = new MySqlConnectionManager("connectionstring");
            var result            = connectionManager.SplitScriptIntoCommands(multiCommand);

            result.Count().ShouldBe(2);
        }
Example #11
0
        /// <summary>
        /// Opens a connection to a mysql server.
        /// </summary>
        public bool real_connect(Context ctx, string host = null, string username = null, string passwd = null, string dbname = "", int port = -1, string socket = null, int flags = 0)
        {
            var    config            = ctx.Configuration.Get <MySqlConfiguration>();
            int    connectiontimeout = 0;
            string characterset      = "utf8mb4"; // default characterset that solves all the problems

            if (_lazyoptions != null)
            {
                PhpValue value;
                if (_lazyoptions.TryGetValue(Constants.MYSQLI_OPT_CONNECT_TIMEOUT, out value))
                {
                    connectiontimeout = (int)value.ToLong();
                }
                if (_lazyoptions.TryGetValue(Constants.MYSQLI_SET_CHARSET_NAME, out value))
                {
                    characterset = value.ToStringOrThrow(ctx);
                }
            }

            // string $host = ini_get("mysqli.default_host")
            // string $username = ini_get("mysqli.default_user")
            // string $passwd = ini_get("mysqli.default_pw")
            // string $dbname = ""
            // int $port = ini_get("mysqli.default_port")
            // string $socket = ini_get("mysqli.default_socket")

            var connection_string = MySql.BuildConnectionString(config, ref host, username, passwd,
                                                                flags: (MySql.ConnectFlags)flags,
                                                                connectiontimeout: connectiontimeout,
                                                                characterset: characterset);

            _connection = MySqlConnectionManager.GetInstance(ctx)
                          .CreateConnection(connection_string, false, -1, out bool success);

            if (success)
            {
                _connection.Server = host;

                if (!string.IsNullOrEmpty(dbname))
                {
                    _connection.SelectDb(dbname);
                }
            }
            else
            {
                MySqliContextData.GetContextData(ctx).LastConnectionError
                      = connect_error
                      = _connection.GetLastErrorMessage();
            }

            //
            return(success);
        }
Example #12
0
        public void DoesNotGetStuckInSkipWhitespace()
        {
            var command           = @"DELIMITER $$
CREATE PROCEDURE TEST(IN statement TEXT)
BEGIN
END$$
DELIMITER;
";
            var connectionManager = new MySqlConnectionManager("connectionstring");
            var t = Task.Run(() => connectionManager.SplitScriptIntoCommands(command)).Wait(TimeSpan.FromSeconds(1));

            t.ShouldBeTrue();
        }
 internal void DeleteStaff(int id)
 {
     using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
     {
         if (MySqlConnectionManager.OpenConnection(conn))
         {
             using (MySqlCommand command = new MySqlCommand("DELETE FROM checkDB.`staff` WHERE staff.idStaff = " + Convert.ToString(id), conn))
             {
                 command.ExecuteNonQuery();
             }
             MySqlConnectionManager.CloseConnection(conn);
         }
     }
 }
 internal void CreateCheckDisplayRow(CheckDisplayRow row)
 {
     using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
     {
         if (MySqlConnectionManager.OpenConnection(conn))
         {
             string commandtext = "CALL CreateCheck(@STORENUM,@BANKNAME,@RNUM,@ANUM,@CNUM,@FIRSTNAME,@LASTNAME,@FIRSTNAME2,@LASTNAME2,@INADDRESS,@INCITY,@INSTATE,@INZIPCODE,@PHONE,@CHECKAMOUNT,@CHECKDATE)";
             using (MySqlCommand command = new MySqlCommand(commandtext, conn))
             {
                 command.Parameters.Add("@STORENUM", MySqlDbType.Int32);
                 command.Parameters["@STORENUM"].Value = row.idStore;
                 command.Parameters.Add("@BANKNAME", MySqlDbType.VarChar);
                 command.Parameters["@BANKNAME"].Value = row.bName;
                 command.Parameters.Add("@ANUM", MySqlDbType.Int32);
                 command.Parameters["@ANUM"].Value = row.idAccount;
                 command.Parameters.Add("@RNUM", MySqlDbType.Int32);
                 command.Parameters["@RNUM"].Value = row.routingNum;
                 command.Parameters.Add("@CNUM", MySqlDbType.Int32);
                 command.Parameters["@CNUM"].Value = row.checkNum;
                 command.Parameters.Add("@FIRSTNAME", MySqlDbType.VarChar);
                 command.Parameters["@FIRSTNAME"].Value = row.fName;
                 command.Parameters.Add("@LASTNAME", MySqlDbType.VarChar);
                 command.Parameters["@LASTNAME"].Value = row.lName;
                 command.Parameters.Add("@FIRSTNAME2", MySqlDbType.VarChar);
                 command.Parameters["@FIRSTNAME2"].Value = (row.fName2 != null && row.fName2 != "") ? row.fName2 : null;
                 command.Parameters.Add("@LASTNAME2", MySqlDbType.VarChar);
                 command.Parameters["@LASTNAME2"].Value = (row.lName2 != null && row.lName2 != "") ? row.lName2 : null;
                 command.Parameters.Add("@INADDRESS", MySqlDbType.VarChar);
                 command.Parameters["@INADDRESS"].Value = row.address;
                 command.Parameters.Add("@INCITY", MySqlDbType.VarChar);
                 command.Parameters["@INCITY"].Value = row.city;
                 command.Parameters.Add("@INSTATE", MySqlDbType.VarChar);
                 command.Parameters["@INSTATE"].Value = row.state;
                 command.Parameters.Add("@INZIPCODE", MySqlDbType.Int32);
                 command.Parameters["@INZIPCODE"].Value = row.zipcode;
                 command.Parameters.Add("@PHONE", MySqlDbType.VarChar);
                 command.Parameters["@PHONE"].Value = (row.phoneNum != null && row.phoneNum != "") ? row.phoneNum : null;
                 command.Parameters.Add("@CHECKAMOUNT", MySqlDbType.Float);
                 command.Parameters["@CHECKAMOUNT"].Value = row.amount;
                 command.Parameters.Add("@CHECKDATE", MySqlDbType.DateTime);
                 command.Parameters["@CHECKDATE"].Value = row.dateWritten;
                 command.ExecuteNonQuery();
             }
             MySqlConnectionManager.CloseConnection(conn);
         }
     }
 }
        public void ParsesOutBeginningDelimiter()
        {
            var multiCommand = new StringBuilder()
                               .AppendLine("DELIMITER $$")
                               .AppendLine("CREATE TABLE 'ZIP'$$")
                               .Append("CREATE TABLE IF NOT EXISTS 'BAR';");

            var connectionManager = new MySqlConnectionManager("connectionstring");
            var result            = connectionManager.SplitScriptIntoCommands(multiCommand.ToString())
                                    .ToArray();

            result.ShouldBe(new[]
            {
                "CREATE TABLE 'ZIP'",
                "CREATE TABLE IF NOT EXISTS 'BAR';"
            });
        }
        // FUNCTION: Adds a new check to the database
        // RETURNS: Returns the check added to confirm that it was added
        internal Check AddCheck(Check check)
        {
            string commandstring = "INSERT INTO checkDB.`chekue` AS checks (idCheck, idAccount, idStore, checkNum, amount, dateWritten) VALUES ({VALUESTRING})";
            string valuestring   = "" + check.IdCheck + "," + check.IdAccount + "," + check.IdStore + "," + check.CheckNum + "," + check.Amount + "," + check.DateWritten.ToString("yyyy-MM-dd");

            commandstring = commandstring.Replace("{VALUESTRING}", valuestring);
            using (MySqlConnection conn = new MySqlConnection(_connectionString))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    using (MySqlCommand command = new MySqlCommand(commandstring, conn))
                    {
                        command.ExecuteNonQuery();
                    }
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
            return(check);
        }
        internal IEnumerable <Staff> RetrieveAllStaff()
        {
            var staff       = new List <Staff>();
            var staffMember = new Staff();

            using (MySqlConnection conn = new MySqlConnection(PredatorConstants.CONNECTION_STRING))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    using (MySqlCommand command = new MySqlCommand("SELECT * FROM checkDB.`staff`", conn))
                    {
                        MySqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            staffMember = new Staff()
                            {
                                /*IdCheck = reader.GetInt32("idCheck"),
                                 * IdAccount = reader.GetInt32("idAccount"),
                                 * IdStore = reader.GetInt32("idStore"),
                                 * CheckNum = reader.GetInt32("checkNum"),
                                 * Amount = reader.GetFloat("amount"),
                                 * DateWritten = reader.GetDateTime("dateWritten"),
                                 * AmountPaid = (!reader.IsDBNull(reader.GetOrdinal("amountPaid"))) ? reader.GetFloat("amountPaid") : -1,
                                 * PaidDate = (!reader.IsDBNull(reader.GetOrdinal("paidDate"))) ? reader.GetDateTime("paidDate") : new DateTime(0)*/
                                idStaff      = reader.GetInt32("idStaff"),
                                fName        = reader.GetString("fName"),
                                lName        = reader.GetString("lName"),
                                username     = reader.GetString("username"),
                                password     = reader.GetString("password"),
                                email        = reader.GetString("email"),
                                accessLevel  = reader.GetInt32("accessLevel"),
                                creationDate = reader.GetDateTime("creationDate")
                            };
                            staff.Add(staffMember);
                        }
                    }
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }
            return(staff);
        }
Example #18
0
        internal IEnumerable <Store> GetAll()
        {
            var stores = new List <Store>();

            using (var conn = new MySqlConnection(_connectionString))
            {
                if (MySqlConnectionManager.OpenConnection(conn))
                {
                    using (var command = new MySqlCommand("SELECT * FROM checkDB.`store`", conn))
                    {
                        MySqlDataReader reader = command.ExecuteReader();
                        while (reader.Read())
                        {
                            stores.Add(new Store()
                            {
                                IdStore      = reader.GetInt32("idStore"),
                                IdStoreGroup = reader.GetInt32("idStoreGroup"),
                                SName        = reader.GetString("sName"),
                                Address      = reader.GetString("address"),
                                City         = reader.GetString("city"),
                                State        = reader.GetString("state"),
                                Zipcode      = reader.GetInt32("zipcode")

                                               //IdCheck = reader.GetInt32("idCheck"),
                                               //IdAccount = reader.GetInt32("idAccount"),
                                               //IdStore = reader.GetInt32("idStore"),
                                               //CheckNum = reader.GetInt32("checkNum"),
                                               //Amount = reader.GetFloat("amount"),
                                               //DateWritten = reader.GetDateTime("dateWritten"),
                                               //AmountPaid = (!reader.IsDBNull(reader.GetOrdinal("amountPaid"))) ? reader.GetFloat("amountPaid") : -1,
                                               //PaidDate = (!reader.IsDBNull(reader.GetOrdinal("paidDate"))) ? reader.GetDateTime("paidDate") : new DateTime(0)
                            });
                        }
                    }
                    MySqlConnectionManager.CloseConnection(conn);
                }
            }

            return(stores);
        }
        public void TestDataflow_MySql_to_List()
        {
            string ServerName = "";

            if (string.IsNullOrEmpty(ServerName))
            {
                return;
            }
            MySqlConnectionManager MyTestDb = new MySqlConnectionManager(ServerName, "TestDB", "", "");


            using (MyTestDb)
            {
                MySqlSource <Datensatz_MySql_to_List> MySqlDBSource = new MySqlSource <Datensatz_MySql_to_List>(MyTestDb.getNewMySqlConnection()
                                                                                                                , "SELECT Tag, Monat FROM test"
                                                                                                                );
                MySqlDBSource.DataMappingMethod = ReaderAdapter_MySql_to_List.Read;

                ListDestination <Datensatz> destination = new ListDestination <Datensatz>();

                Graph g = new Graph();

                g.GetVertex(0, MySqlDBSource);
                g.GetVertex(1, new RowTransformation <Datensatz_MySql_to_List>(RowTransformationDB));
                g.GetVertex(2, new RowTransformation <Datensatz_MySql_to_List>(RowTransformationDB2));
                g.GetVertex(3, destination);

                g.AddEdge(0, 1); // connect 0 to 1
                g.AddEdge(1, 2); // connect 1 to 2
                g.AddEdge(2, 3); // connect 2 to 3



                DataFlowTask <Datensatz> .Execute("Test dataflow task", 10000, 1, g);

                //TestHelper.VisualizeGraph(g);

                //Assert.AreEqual(4, new ExecuteSQLTask(MyTestDb.MySqlConnection).ExecuteScalar(string.Format("select count(*) from {0}", destObject)));
            }
        }
        public void ParsesOutDelimiter()
        {
            var multiCommand = "USE `test`;";

            multiCommand += "CREATE TABLE IF NOT EXISTS 'FOO';";
            multiCommand += Environment.NewLine;
            multiCommand += "DELIMITER $$";
            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE 'ZIP'$$";
            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE IF NOT EXISTS 'BAR';";

            var connectionManager = new MySqlConnectionManager("connectionstring");
            var result            = connectionManager.SplitScriptIntoCommands(multiCommand);

            var enumerable = result as string[] ?? result.ToArray();

            enumerable.Length.ShouldBe(4);
            enumerable[0].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[1].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[2].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[3].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
        }
Example #21
0
 public DataContext() : base((MySqlConnectionManager.New().GetConnection() as MySqlConnection))
 {
     Configuration.LazyLoadingEnabled   = true;
     Configuration.ProxyCreationEnabled = true;
     Database.SetInitializer(new DataInitializer());
 }