Esempio n. 1
0
        /**
         *   Method to convert strings of a sql-result to the hinted datatype.
         *   Return or false if the data conversion succeeds or fails, respectively.
         *   @param sqlString is the string to convert
         *   @param get is the hint on the final data type of the conversion
         *   @param output is the object where the resulting type-converted string will be stored into
         */
        public static bool TrySqlStringToData(string sqlString, SQLiteGetType t, out object output)
        {
            if (sqlString != null)
            {
                switch (t)
                {
                case (SQLiteGetType.GetBoolean):
                    bool outBool = false;
                    if (bool.TryParse(sqlString, out outBool))
                    {
                        output = outBool;
                        return(true);
                    }
                    else if (sqlString.Equals("0"))
                    {
                        output = false;
                        return(true);
                    }
                    else if (sqlString.Equals("1"))
                    {
                        output = true;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetByte):
                    byte outByte = 0;
                    if (byte.TryParse(sqlString, out outByte))
                    {
                        output = outByte;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetChar):
                    char outChar = '0';
                    if (char.TryParse(sqlString, out outChar))
                    {
                        output = outChar;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetDateTime):
                    DateTime outDateTime = new DateTime();
                    if (DateTime.TryParse(sqlString, out outDateTime))
                    {
                        output = outDateTime;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetDecimal):
                    decimal outDecimal = 0;
                    if (decimal.TryParse(sqlString, out outDecimal))
                    {
                        output = outDecimal;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetDouble):
                    double outDouble = 0;
                    if (double.TryParse(sqlString, out outDouble))
                    {
                        output = outDouble;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetFloat):
                    float outFloat = 0;
                    if (float.TryParse(sqlString, out outFloat))
                    {
                        output = outFloat;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetGuid):
                    Guid outGuid = Guid.Empty;
                    if (Guid.TryParse(sqlString, out outGuid))
                    {
                        output = outGuid;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetInt16):
                    short outInt16 = 0;
                    if (short.TryParse(sqlString, out outInt16))
                    {
                        output = outInt16;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetInt32):
                    int outInt32 = 0;
                    if (int.TryParse(sqlString, out outInt32))
                    {
                        output = outInt32;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetInt64):
                    long outInt64 = 0;
                    if (long.TryParse(sqlString, out outInt64))
                    {
                        output = outInt64;
                        return(true);
                    }
                    else
                    {
                        Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                            + "' with " + t + " in SqlStringToData.");
                        break;
                    }

                case (SQLiteGetType.GetString):
                    output = sqlString;
                    return(true);

                default:
                    Log.Logger.LogError("Could not convert sql-result-string '" + sqlString
                                        + "' with " + t + " in SqlStringToData because this datatype is not supported.");
                    break;
                }
            }

            output = null;
            return(false);
        }
Esempio n. 2
0
 public ColumnGetTypeInfo(string colName, SQLiteGetType getType)
 {
     this.colName = colName;
     this.getType = getType;
 }