Esempio n. 1
0
 public long LookupSoupEntryId(string soupName, string fieldPath, string fieldValue)
 {
     lock (smartlock)
     {
         DBHelper db            = Database;
         string   soupTableName = db.GetSoupTableName(soupName);
         if (String.IsNullOrWhiteSpace(soupTableName))
         {
             throw new SmartStoreException("Soup: " + soupName + " does not exist");
         }
         string columnName = db.GetColumnNameForPath(soupName, fieldPath);
         using (SQLiteStatement statement = db.Query(soupTableName, new[] { IdCol }, String.Empty, String.Empty,
                                                     columnName + " = ?", fieldValue))
         {
             if (statement.DataCount > 1)
             {
                 throw new SmartStoreException(String.Format(
                                                   "There are more than one soup elements where {0} is {1}", fieldPath, fieldValue));
             }
             if (statement.DataCount == 1)
             {
                 return(statement.GetInteger(0));
             }
         }
         return(-1); // not found
     }
 }
 /// <summary>
 ///     Helper to retrieve data.
 /// </summary>
 /// <param name="statement"></param>
 /// <param name="position"></param>
 /// <returns></returns>
 private object GetObject(SQLiteStatement statement, int position)
 {
     try
     {
         return(statement.GetText(position));
     }
     catch (Exception e)
     {
     }
     try
     {
         return(statement.GetInteger(position));
     }
     catch (Exception e)
     {
     }
     try
     {
         return(statement.GetFloat(position));
     }
     catch (Exception e)
     {
     }
     return(null);
 }
Esempio n. 3
0
 private object GetObject(SQLiteStatement statement, int position)
 {
     if (statement[position] == null)
     {
         return(null);
     }
     if (statement[position].GetType().Name == "String")
     {
         return(statement.GetText(position));
     }
     if (intTypes.Contains(statement[position].GetType().Name))
     {
         return(statement.GetInteger(position));
     }
     //
     //fallback try to detect type using exceptions
     //
     try
     {
         return(statement.GetText(position));
     }
     catch (Exception e)
     {
         PlatformAdapter.SendToCustomLogger(e, LoggingLevel.Error);
     }
     try
     {
         return(statement.GetInteger(position));
     }
     catch (Exception e)
     {
         PlatformAdapter.SendToCustomLogger(e, LoggingLevel.Error);
     }
     try
     {
         return(statement.GetFloat(position));
     }
     catch (Exception e)
     {
         PlatformAdapter.SendToCustomLogger(e, LoggingLevel.Error);
     }
     return(null);
 }
Esempio n. 4
0
 protected string GetSoupTableNameFromDb(string soupName)
 {
     using (
         SQLiteStatement stmt = Query(SmartStore.SoupNamesTable, new[] { SmartStore.IdCol }, String.Empty,
                                      String.Empty,
                                      SmartStore.SoupNamePredicate, soupName))
     {
         if (stmt.DataCount == 0)
         {
             return(null);
         }
         return(SmartStore.GetSoupTableName(stmt.GetInteger(SmartStore.IdCol)));
     }
 }