GetMySqlDateTime() public méthode

public GetMySqlDateTime ( int column ) : MySqlDateTime
column int
Résultat MySql.Data.Types.MySqlDateTime
Exemple #1
0
 public static DateTime GetDateTimeFromRdr(MySql.Data.MySqlClient.MySqlDataReader rdr, string column)
 {
     try
     {
         int ord = rdr.GetOrdinal(column);
         //if (rdr[ord] == DBNull.Value) return DateTime.MinValue;
         string typeName = rdr.GetDataTypeName(ord);
         if (typeName == "DATE")
         {
             rdr.GetMySqlDateTime(ord).GetDateTime();
         }
         return((DateTime)rdr[column]);
     }
     catch (Exception exc)
     {
         log.Error("GetDateTimeFromRdr", exc);
         return(DateTime.Now);
     }
 }
Exemple #2
0
        public static DateTime GetMySQLDateTime(MySqlDataReader mySQLDataReader, String column)
        {
            DateTime dateTime = DateTime.MinValue;

            try
            {
                int index = mySQLDataReader.GetOrdinal(column);
                if (!mySQLDataReader.IsDBNull(index))
                {
                    MySqlDateTime mySQLDateTime = mySQLDataReader.GetMySqlDateTime(column);
                    if (mySQLDateTime.Day > 0)
                    {
                        dateTime = mySQLDateTime.GetDateTime();
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }

            return dateTime;
        }
        private TrackingEntry readEntry(MySqlDataReader reader)
        {
            TrackingEntry currentEntry = new TrackingEntry();

            currentEntry.entryID = reader.GetInt32(0);
            currentEntry.taggerID = reader.GetInt32(1);
            currentEntry.type = reader.GetChar(2);
            currentEntry.isTagged = reader.GetBoolean(3);
            currentEntry.taggerName = reader.GetString(4);
            currentEntry.entryDate = ((DateTime)reader.GetMySqlDateTime(5)).ToString("yyyy-MM-dd HH:mm:ss");

            if (reader.IsDBNull(6))
                currentEntry.tagNumber = -1;
            else
                currentEntry.tagNumber = reader.GetInt32(6);

            currentEntry.species = reader.GetString(7);

            if (reader.IsDBNull(8))
                currentEntry.city = "";
            else
                currentEntry.city = reader.GetString(8);

            if (reader.IsDBNull(9))
                currentEntry.state = "";
            else
                currentEntry.state = reader.GetString(9);

            if (reader.IsDBNull(10))
                currentEntry.country = "";
            else
                currentEntry.country = reader.GetString(10);

            if (reader.IsDBNull(11))
                currentEntry.longitude = "";
            else
                currentEntry.longitude = reader.GetString(11);

            if (reader.IsDBNull(12))
                currentEntry.latitude = "";
            else
                currentEntry.latitude = reader.GetString(12);

            if (reader.IsDBNull(13))
                currentEntry.temperature = "";
            else
                currentEntry.temperature = reader.GetString(13);

            if (reader.IsDBNull(14))
                currentEntry.precipitation = "";
            else
                currentEntry.precipitation = reader.GetString(14);

            if (reader.IsDBNull(15))
                currentEntry.windSpeed = "";
            else
                currentEntry.windSpeed = reader.GetString(15);

            if (reader.IsDBNull(16))
                currentEntry.windDirection = "";
            else
                currentEntry.windDirection = reader.GetString(16);

            return currentEntry;
        }
        public static string ConvertToSqlFormat(MySqlDataReader rdr, int colIndex, bool wrapStringWithSingleQuote, bool escapeStringSequence, MySqlColumn col)
        {
            object ob = rdr[colIndex];

            StringBuilder sb = new StringBuilder();

            if (ob == null || ob is System.DBNull)
            {
                sb.AppendFormat("NULL");
            }
            else if (ob is System.String)
            {
                string str = (string)ob;

                if (escapeStringSequence)
                    str = QueryExpress.EscapeStringSequence(str);

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");

                sb.Append(str);

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");
            }
            else if (ob is System.Boolean)
            {
                sb.AppendFormat(Convert.ToInt32(ob).ToString());
            }
            else if (ob is System.Byte[])
            {
                if (((byte[])ob).Length == 0)
                {
                    if (wrapStringWithSingleQuote)
                        return "''";
                    else
                        return "";
                }
                else
                {
                    sb.AppendFormat(CryptoExpress.ConvertByteArrayToHexString((byte[])ob));
                }
            }
            else if (ob is short)
            {
                sb.AppendFormat(((short)ob).ToString(_numberFormatInfo));
            }
            else if (ob is int)
            {
                sb.AppendFormat(((int)ob).ToString(_numberFormatInfo));
            }
            else if (ob is long)
            {
                sb.AppendFormat(((long)ob).ToString(_numberFormatInfo));
            }
            else if (ob is ushort)
            {
                sb.AppendFormat(((ushort)ob).ToString(_numberFormatInfo));
            }
            else if (ob is uint)
            {
                sb.AppendFormat(((uint)ob).ToString(_numberFormatInfo));
            }
            else if (ob is ulong)
            {
                sb.AppendFormat(((ulong)ob).ToString(_numberFormatInfo));
            }
            else if (ob is double)
            {
                sb.AppendFormat(((double)ob).ToString(_numberFormatInfo));
            }
            else if (ob is decimal)
            {
                sb.AppendFormat(((decimal)ob).ToString(_numberFormatInfo));
            }
            else if (ob is float)
            {
                sb.AppendFormat(((float)ob).ToString(_numberFormatInfo));
            }
            else if (ob is byte)
            {
                sb.AppendFormat(((byte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is sbyte)
            {
                sb.AppendFormat(((sbyte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is TimeSpan)
            {
                TimeSpan ts = (TimeSpan)ob;

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");

                sb.AppendFormat(ts.Hours.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Minutes.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Seconds.ToString().PadLeft(2, '0'));

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");
            }
            else if (ob is System.DateTime)
            {
                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");

                sb.AppendFormat(((DateTime)ob).ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));

                if (col.TimeFractionLength > 0)
                {
                    sb.Append(".");
                    string _microsecond = rdr.GetMySqlDateTime(colIndex).Microsecond.ToString();
                    if (_microsecond.Length < col.TimeFractionLength)
                    {
                        _microsecond = _microsecond.PadLeft(col.TimeFractionLength, '0');
                    }
                    else if (_microsecond.Length > col.TimeFractionLength)
                    {
                        _microsecond = _microsecond.Substring(0, col.TimeFractionLength);
                    }
                    sb.Append(_microsecond.ToString().PadLeft(col.TimeFractionLength, '0'));
                }

                if (wrapStringWithSingleQuote)
                    sb.AppendFormat("'");
            }
            else if (ob is MySql.Data.Types.MySqlDateTime)
            {
                MySql.Data.Types.MySqlDateTime mdt = (MySql.Data.Types.MySqlDateTime)ob;

                if (mdt.IsNull)
                {
                    sb.AppendFormat("NULL");
                }
                else
                {
                    if (mdt.IsValidDateTime)
                    {
                        DateTime dtime = mdt.Value;

                        if (wrapStringWithSingleQuote)
                            sb.AppendFormat("'");

                        if (col.MySqlDataType == "datetime")
                            sb.AppendFormat(dtime.ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));
                        else if (col.MySqlDataType == "date")
                            sb.AppendFormat(dtime.ToString("yyyy-MM-dd", _dateFormatInfo));
                        else if (col.MySqlDataType == "time")
                            sb.AppendFormat(dtime.ToString("HH:mm:ss", _dateFormatInfo));
                        else
                            sb.AppendFormat(dtime.ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));

                        if(col.TimeFractionLength > 0)
                        {
                            sb.Append(".");
                            sb.Append(((MySql.Data.Types.MySqlDateTime)ob).Microsecond.ToString().PadLeft(col.TimeFractionLength, '0'));
                        }

                        if (wrapStringWithSingleQuote)
                            sb.AppendFormat("'");
                    }
                    else
                    {
                        if (wrapStringWithSingleQuote)
                            sb.AppendFormat("'");

                        if (col.MySqlDataType == "datetime")
                            sb.AppendFormat("0000-00-00 00:00:00");
                        else if (col.MySqlDataType == "date")
                            sb.AppendFormat("0000-00-00");
                        else if (col.MySqlDataType == "time")
                            sb.AppendFormat("00:00:00");
                        else
                            sb.AppendFormat("0000-00-00 00:00:00");

                        if (col.TimeFractionLength > 0)
                        {
                            sb.Append(".".PadRight(col.TimeFractionLength, '0'));
                        }

                        if (wrapStringWithSingleQuote)
                            sb.AppendFormat("'");
                    }
                }
            }
            else if (ob is System.Guid)
            {
                if (col.MySqlDataType == "binary(16)")
                {
                    sb.Append(CryptoExpress.ConvertByteArrayToHexString(((Guid)ob).ToByteArray()));
                }
                else if (col.MySqlDataType == "char(36)")
                {
                    if (wrapStringWithSingleQuote)
                        sb.AppendFormat("'");

                    sb.Append(ob);

                    if (wrapStringWithSingleQuote)
                        sb.AppendFormat("'");
                }
                else
                {
                    if (wrapStringWithSingleQuote)
                        sb.AppendFormat("'");

                    sb.Append(ob);

                    if (wrapStringWithSingleQuote)
                        sb.AppendFormat("'");
                }
            }
            else
            {
                throw new Exception("Unhandled data type. Current processing data type: " + ob.GetType().ToString() + ". Please report this bug with this message to the development team.");
            }
            return sb.ToString();
        }
Exemple #5
0
        public static string ConvertToSqlFormat(MySqlDataReader rdr, int colIndex, bool wrapStringWithSingleQuote,
                                                bool escapeStringSequence, MySqlColumn col)
        {
            var ob = rdr[colIndex];

            var sb = new StringBuilder();

            if (ob == null || ob is DBNull)
            {
                sb.AppendFormat("NULL");
            }
            else if (ob is string)
            {
                var str = (string)ob;

                if (escapeStringSequence)
                {
                    str = EscapeStringSequence(str);
                }

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }

                sb.Append(str);

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else if (ob is bool)
            {
                sb.AppendFormat(Convert.ToInt32(ob).ToString());
            }
            else if (ob is byte[])
            {
                if (((byte[])ob).Length == 0)
                {
                    if (wrapStringWithSingleQuote)
                    {
                        return("''");
                    }
                    else
                    {
                        return("");
                    }
                }
                sb.AppendFormat(CryptoExpress.ConvertByteArrayToHexString((byte[])ob));
            }
            else if (ob is short)
            {
                sb.AppendFormat(((short)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is int)
            {
                sb.AppendFormat(((int)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is long)
            {
                sb.AppendFormat(((long)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is ushort)
            {
                sb.AppendFormat(((ushort)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is uint)
            {
                sb.AppendFormat(((uint)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is ulong)
            {
                sb.AppendFormat(((ulong)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is double)
            {
                sb.AppendFormat(((double)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is decimal)
            {
                sb.AppendFormat(((decimal)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is float)
            {
                sb.AppendFormat(((float)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is byte)
            {
                sb.AppendFormat(((byte)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is sbyte)
            {
                sb.AppendFormat(((sbyte)ob).ToString(MySqlNumberFormat));
            }
            else if (ob is TimeSpan)
            {
                var ts = (TimeSpan)ob;

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }

                sb.AppendFormat(ts.Hours.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Minutes.ToString().PadLeft(2, '0'));
                sb.AppendFormat(":");
                sb.AppendFormat(ts.Seconds.ToString().PadLeft(2, '0'));

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else if (ob is DateTime)
            {
                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }

                sb.AppendFormat(((DateTime)ob).ToString("yyyy-MM-dd HH:mm:ss", MySqlDateTimeFormat));

                if (col.TimeFractionLength > 0)
                {
                    sb.Append(".");
                    var microsecond = rdr.GetMySqlDateTime(colIndex).Microsecond.ToString();
                    if (microsecond.Length < col.TimeFractionLength)
                    {
                        microsecond = microsecond.PadLeft(col.TimeFractionLength, '0');
                    }
                    else if (microsecond.Length > col.TimeFractionLength)
                    {
                        microsecond = microsecond.Substring(0, col.TimeFractionLength);
                    }
                    sb.Append(microsecond.PadLeft(col.TimeFractionLength, '0'));
                }

                if (wrapStringWithSingleQuote)
                {
                    sb.AppendFormat("'");
                }
            }
            else if (ob is MySqlDateTime)
            {
                var mdt = (MySqlDateTime)ob;

                if (mdt.IsNull)
                {
                    sb.AppendFormat("NULL");
                }
                else
                {
                    if (mdt.IsValidDateTime)
                    {
                        var dtime = mdt.Value;

                        if (wrapStringWithSingleQuote)
                        {
                            sb.AppendFormat("'");
                        }

                        if (col.MySqlDataType == "datetime")
                        {
                            sb.AppendFormat(dtime.ToString("yyyy-MM-dd HH:mm:ss", MySqlDateTimeFormat));
                        }
                        else if (col.MySqlDataType == "date")
                        {
                            sb.AppendFormat(dtime.ToString("yyyy-MM-dd", MySqlDateTimeFormat));
                        }
                        else if (col.MySqlDataType == "time")
                        {
                            sb.AppendFormat(dtime.ToString("HH:mm:ss", MySqlDateTimeFormat));
                        }
                        else
                        {
                            sb.AppendFormat(dtime.ToString("yyyy-MM-dd HH:mm:ss", MySqlDateTimeFormat));
                        }

                        if (col.TimeFractionLength > 0)
                        {
                            sb.Append(".");
                            sb.Append(((MySqlDateTime)ob).Microsecond.ToString().PadLeft(col.TimeFractionLength, '0'));
                        }

                        if (wrapStringWithSingleQuote)
                        {
                            sb.AppendFormat("'");
                        }
                    }
                    else
                    {
                        if (wrapStringWithSingleQuote)
                        {
                            sb.AppendFormat("'");
                        }

                        if (col.MySqlDataType == "datetime")
                        {
                            sb.AppendFormat("0000-00-00 00:00:00");
                        }
                        else if (col.MySqlDataType == "date")
                        {
                            sb.AppendFormat("0000-00-00");
                        }
                        else if (col.MySqlDataType == "time")
                        {
                            sb.AppendFormat("00:00:00");
                        }
                        else
                        {
                            sb.AppendFormat("0000-00-00 00:00:00");
                        }

                        if (col.TimeFractionLength > 0)
                        {
                            sb.Append(".".PadRight(col.TimeFractionLength, '0'));
                        }

                        if (wrapStringWithSingleQuote)
                        {
                            sb.AppendFormat("'");
                        }
                    }
                }
            }
            else if (ob is Guid)
            {
                switch (col.MySqlDataType)
                {
                case "binary(16)":
                    sb.Append(CryptoExpress.ConvertByteArrayToHexString(((Guid)ob).ToByteArray()));
                    break;

                case "char(36)":
                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("'");
                    }

                    sb.Append(ob);

                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("'");
                    }
                    break;

                default:
                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("'");
                    }

                    sb.Append(ob);

                    if (wrapStringWithSingleQuote)
                    {
                        sb.AppendFormat("'");
                    }
                    break;
                }
            }
            else
            {
                throw new Exception("Unhandled data type. Current processing data type: " + ob.GetType() +
                                    ". Please report this bug with this message to the development team.");
            }
            return(sb.ToString());
        }
        public static void CleanInactiveUsers()
        {
            CloseReader();

            Logger.Log(LogType.Event, "Clearing inactive users from database");
            try
            {
                string query = String.Format(
                    "SELECT * FROM {0} WHERE (Active='0')",
                    playerTableName);

                MySqlCommand cmd = new MySqlCommand(query, dbConnection);
                dbReader = cmd.ExecuteReader();

                while (dbReader.Read())
                {
                    string name = dbReader.GetString("Name");
                    string email = dbReader.GetString("Email");
                    DateTime time = dbReader.GetMySqlDateTime("RegDate").GetDateTime();
                    if (time.AddDays(Properties.Settings.Default.playerinactivelimit).CompareTo(DateTime.Now) < 0)
                    {
                        query = String.Format(
                            "DELETE FROM {0} WHERE (Name='{1:0}')",
                            playerTableName, name);

                        cmd = new MySqlCommand(query, dbConnection);
                        dbReader = cmd.ExecuteReader();
                        CloseReader();

                        Logger.Log(LogType.Event, name + " was deleted from database due to inactivity");

                        Email(
                        "Poker Account Expired",
                        String.Format(
                            "Hello, your account ({0}) on Circle of Current Poker has expired.",
                            name),
                        email
                        );
                    }
                }

                CloseReader();
            }
            catch (Exception ex)
            {
                Logger.Log("While cleaning inactive users", ex);
            }
        }
Exemple #7
0
        public static string ConvertToSqlFormat(MySqlDataReader rdr, int colIndex, bool wrapStringWithSingleQuote, bool escapeStringSequence, MySqlColumn col)
        {
            object ob = rdr[colIndex];

            StringBuilder sb = new StringBuilder();

            if (ob == null || ob is System.DBNull)
            {
                sb.Append("NULL");
            }
            else if (ob is System.String)
            {
                string str = (string)ob;

                if (escapeStringSequence)
                {
                    str = QueryExpress.EscapeStringSequence(str);
                }

                if (wrapStringWithSingleQuote)
                {
                    sb.Append("'");
                }

                sb.Append(str);

                if (wrapStringWithSingleQuote)
                {
                    sb.Append("'");
                }
            }
            else if (ob is System.Boolean)
            {
                sb.Append(Convert.ToInt32(ob).ToString());
            }
            else if (ob is System.Byte[])
            {
                if (((byte[])ob).Length == 0)
                {
                    if (wrapStringWithSingleQuote)
                    {
                        return("''");
                    }
                    else
                    {
                        return("");
                    }
                }
                else
                {
                    sb.Append(CryptoExpress.ConvertByteArrayToHexString((byte[])ob));
                }
            }
            else if (ob is short)
            {
                sb.Append(((short)ob).ToString(_numberFormatInfo));
            }
            else if (ob is int)
            {
                sb.Append(((int)ob).ToString(_numberFormatInfo));
            }
            else if (ob is long)
            {
                sb.Append(((long)ob).ToString(_numberFormatInfo));
            }
            else if (ob is ushort)
            {
                sb.Append(((ushort)ob).ToString(_numberFormatInfo));
            }
            else if (ob is uint)
            {
                sb.Append(((uint)ob).ToString(_numberFormatInfo));
            }
            else if (ob is ulong)
            {
                sb.Append(((ulong)ob).ToString(_numberFormatInfo));
            }
            else if (ob is double)
            {
                sb.Append(((double)ob).ToString(_numberFormatInfo));
            }
            else if (ob is decimal)
            {
                sb.Append(((decimal)ob).ToString(_numberFormatInfo));
            }
            else if (ob is float)
            {
                sb.Append(((float)ob).ToString(_numberFormatInfo));
            }
            else if (ob is byte)
            {
                sb.Append(((byte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is sbyte)
            {
                sb.Append(((sbyte)ob).ToString(_numberFormatInfo));
            }
            else if (ob is TimeSpan)
            {
                TimeSpan ts = (TimeSpan)ob;

                if (wrapStringWithSingleQuote)
                {
                    sb.Append("'");
                }

                sb.Append(ts.Hours.ToString("D2"))
                .Append(":")
                .Append(ts.Minutes.ToString("D2"))
                .Append(":")
                .Append(ts.Seconds.ToString("D2"))
                .Append(".")
                .Append(ts.Milliseconds.ToString("D3"));
                if (wrapStringWithSingleQuote)
                {
                    sb.Append("'");
                }
            }
            else if (ob is System.DateTime)
            {
                if (wrapStringWithSingleQuote)
                {
                    sb.Append("'");
                }
                sb.Append(((DateTime)ob).ToString("yyyy-MM-dd HH:mm:ss.fff", _dateFormatInfo));
                if (col.TimeFractionLength > 0)
                {
                    sb.Append(".");
                    string _millisecond = rdr.GetMySqlDateTime(colIndex).Millisecond.ToString();
                    if (_millisecond.Length < col.TimeFractionLength)
                    {
                        _millisecond = _millisecond.PadLeft(col.TimeFractionLength, '0');
                    }
                    else if (_millisecond.Length > col.TimeFractionLength)
                    {
                        _millisecond = _millisecond.Substring(0, col.TimeFractionLength);
                    }
                    sb.Append(_millisecond.ToString().PadLeft(col.TimeFractionLength, '0'));
                }

                if (wrapStringWithSingleQuote)
                {
                    sb.Append("'");
                }
            }
            else if (ob is MySql.Data.Types.MySqlDateTime)
            {
                MySql.Data.Types.MySqlDateTime mdt = (MySql.Data.Types.MySqlDateTime)ob;

                if (mdt.IsNull)
                {
                    sb.Append("NULL");
                }
                else
                {
                    if (mdt.IsValidDateTime)
                    {
                        DateTime dtime = mdt.Value;

                        if (wrapStringWithSingleQuote)
                        {
                            sb.Append("'");
                        }

                        if (col.MySqlDataType == "datetime")
                        {
                            sb.Append(dtime.ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));
                        }
                        else if (col.MySqlDataType == "date")
                        {
                            sb.Append(dtime.ToString("yyyy-MM-dd", _dateFormatInfo));
                        }
                        else if (col.MySqlDataType == "time")
                        {
                            sb.Append(dtime.ToString("HH:mm:ss", _dateFormatInfo));
                        }
                        else
                        {
                            sb.Append(dtime.ToString("yyyy-MM-dd HH:mm:ss", _dateFormatInfo));
                        }

                        if (col.TimeFractionLength > 0)
                        {
                            sb.Append(".");
                            sb.Append(((MySql.Data.Types.MySqlDateTime)ob).Millisecond.ToString().PadLeft(col.TimeFractionLength, '0'));
                        }

                        if (wrapStringWithSingleQuote)
                        {
                            sb.Append("'");
                        }
                    }
                    else
                    {
                        if (wrapStringWithSingleQuote)
                        {
                            sb.Append("'");
                        }

                        if (col.MySqlDataType == "datetime")
                        {
                            sb.Append("0000-00-00 00:00:00");
                        }
                        else if (col.MySqlDataType == "date")
                        {
                            sb.Append("0000-00-00");
                        }
                        else if (col.MySqlDataType == "time")
                        {
                            sb.Append("00:00:00");
                        }
                        else
                        {
                            sb.Append("0000-00-00 00:00:00");
                        }

                        if (col.TimeFractionLength > 0)
                        {
                            sb.Append(".".PadRight(col.TimeFractionLength, '0'));
                        }

                        if (wrapStringWithSingleQuote)
                        {
                            sb.Append("'");
                        }
                    }
                }
            }
            else if (ob is System.Guid)
            {
                if (col.MySqlDataType == "binary(16)")
                {
                    sb.Append(CryptoExpress.ConvertByteArrayToHexString(((Guid)ob).ToByteArray()));
                }
                else if (col.MySqlDataType == "char(36)")
                {
                    if (wrapStringWithSingleQuote)
                    {
                        sb.Append("'");
                    }

                    sb.Append(ob);

                    if (wrapStringWithSingleQuote)
                    {
                        sb.Append("'");
                    }
                }
                else
                {
                    if (wrapStringWithSingleQuote)
                    {
                        sb.Append("'");
                    }

                    sb.Append(ob);

                    if (wrapStringWithSingleQuote)
                    {
                        sb.Append("'");
                    }
                }
            }
            else
            {
                throw new Exception("Unhandled data type. Current processing data type: " + ob.GetType().ToString() + ". Please report this bug with this message to the development team.");
            }
            return(sb.ToString());
        }
        public void updateDateValue(String tabela, String campo, OleDbCommand comandoTarget, MySqlDataReader reader, Int16 index, String campoId, Int32 valorId)
        {
            if (!reader.IsDBNull(index))
            {
                comandoTarget.CommandText = "Update " + tabela + " set " + campo + "=cdate('" + reader.GetMySqlDateTime(index) + "') where " + campoId + " = " + valorId; ;
                comandoTarget.ExecuteNonQuery();

            }
        }
        private List<User> readToUser(MySqlDataReader _reader)
        {
            List<User> users = new List<User>();
            string usersQuery = String.Format("SELECT user_type, {0}.users.id, Username, name, dateOfBirth, surname, gender, password, length, weight FROM {0}.users LEFT JOIN {0}.client_bmi_info on {0}.users.id = {0}.client_bmi_info.users_id  ", _database);
            OpenConnection();
            _selectCommand = new MySqlCommand(usersQuery, Connection);


            while (_reader.Read())
            {
                User u;
                int type = _reader.GetInt32(0);
                if (type == 2)
                {
                    u = new Administrator()
                    {
                        Username = _reader.IsDBNull(2) ? null : _reader.GetString(2),
                        Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5),
                        Name = _reader.IsDBNull(3) ? null : _reader.GetString(3),
                        DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4),
                        Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1),
                        Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6)
                    };
                }
                else if (type == 1)
                {
                    u = new Specialist
                    {
                        Username = _reader.IsDBNull(2) ? null : _reader.GetString(2),
                        Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5),
                        Name = _reader.IsDBNull(3) ? null : _reader.GetString(3),
                        DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4),
                        Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1),
                        Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6)
                    };
                }
                else if (_reader.GetInt32(0) == 0)
                {
                    u = new Client
                    {
                        Username = _reader.IsDBNull(2) ? null : _reader.GetString(2),
                        Surname = _reader.IsDBNull(5) ? null : _reader.GetString(5),
                        Name = _reader.IsDBNull(3) ? null : _reader.GetString(3),
                        DateOfBirth = _reader.IsDBNull(4) ? DateTime.MinValue : (DateTime)_reader.GetMySqlDateTime(4),
                        Id = _reader.IsDBNull(1) ? 0 : _reader.GetInt32(1),
                        Gender = _reader.IsDBNull(6) ? null : _reader.GetString(6),
                        Lenght = _reader.IsDBNull(8) ? -1 : _reader.GetDecimal(8),
                        Weight = _reader.IsDBNull(9) ? -1 : _reader.GetDecimal(9)
                    };
                }
                else
                    continue;
                users.Add(u);
            }
            _reader.Close();
            return users;
        }