private List <UserInfoRec> GetUserInfos(IStatement statement) { var result = new List <UserInfoRec>(); foreach (var row in statement.ExecuteQuery()) { var item = new UserInfoRec { #if EMBY ItemId = row.GetString(0), Guid = row.GetGuid(1), UserId = row.GetString(2), LastModified = row.GetInt64(3), Type = row.GetString(4) #else Guid = row.GetGuid(0), UserId = row.GetString(1), LastModified = row.GetInt64(2), Type = row.GetString(3) #endif }; result.Add(item); } return(result); }
private List <ItemRec> GetItems(IStatement statement) { var result = new List <ItemRec>(); foreach (var row in statement.ExecuteQuery()) { var item = new ItemRec { #if EMBY ItemId = row.GetString(0), Guid = row.GetGuid(1), SeriesId = row.IsDBNull(2) ? null : (long?)row.GetInt64(2), Season = row.IsDBNull(3) ? null : (int?)row.GetInt(3), Status = (ItemStatus)row.GetInt(4), LastModified = row.GetInt64(5), Type = row.GetString(6) #else Guid = row.GetGuid(0), SeriesId = row.IsDBNull(1) ? null : (Guid?)row.GetGuid(1), Season = row.IsDBNull(2) ? null : (int?)row.GetInt(2), Status = (ItemStatus)row.GetInt(3), LastModified = row.GetInt64(4), Type = row.GetString(5) #endif }; result.Add(item); } return(result); }
/* * public Set<Integer> getPatterns(String sentId, Integer tokenId) throws SQLException, IOException, ClassNotFoundException { * if(useDBForTokenPatterns){ * Connection conn = SQLConnection.getConnection(); * * String query = "Select patterns from " + tableName + " where sentid=\'" + sentId + "\' and tokenid = " + tokenId; * Statement stmt = conn.createStatement(); * ResultSet rs = stmt.executeQuery(query); * Set<Integer> pats = null; * if(rs.next()){ * byte[] st = (byte[]) rs.getObject(1); * ByteArrayInputStream baip = new ByteArrayInputStream(st); * ObjectInputStream ois = new ObjectInputStream(baip); * pats = (Set<Integer>) ois.readObject(); * * } * conn.close(); * return pats; * } * else * return patternsForEachToken.get(sentId).get(tokenId); * }*/ public override IDictionary <int, ICollection <E> > GetPatternsForAllTokens(string sentId) { try { IConnection conn = SQLConnection.GetConnection(); //Map<Integer, Set<Integer>> pats = new ConcurrentHashMap<Integer, Set<Integer>>(); string query = "Select patterns from " + tableName + " where sentid=\'" + sentId + "\'"; IStatement stmt = conn.CreateStatement(); IResultSet rs = stmt.ExecuteQuery(query); IDictionary <int, ICollection <E> > patsToken = new Dictionary <int, ICollection <E> >(); if (rs.Next()) { byte[] st = (byte[])rs.GetObject(1); ByteArrayInputStream baip = new ByteArrayInputStream(st); ObjectInputStream ois = new ObjectInputStream(baip); patsToken = (IDictionary <int, ICollection <E> >)ois.ReadObject(); } //pats.put(rs.getInt("tokenid"), patsToken); conn.Close(); return(patsToken); } catch (Exception e) { throw new Exception(e); } }
/// <summary>Return rank of 1 gram in google ngeams if it is less than 20k.</summary> /// <remarks>Return rank of 1 gram in google ngeams if it is less than 20k. Otherwise -1.</remarks> public static int Get1GramRank(string str) { string query = null; try { Connect(); str = str.Trim(); if (str.Contains("'")) { str = StringUtils.EscapeString(str, new char[] { '\'' }, '\''); } int ngram = str.Split("\\s+").Length; if (ngram > 1) { return(-1); } string table = "googlengrams_1_ranked20k"; if (!ExistsTable(table)) { return(-1); } string phrase = EscapeString(str); query = "select rank from " + table + " where phrase='" + phrase + "';"; IStatement stmt = connection.CreateStatement(); IResultSet result = stmt.ExecuteQuery(query); if (result.Next()) { return(result.GetInt("rank")); } else { return(-1); } } catch (SQLException e) { log.Info("Error getting count for " + str + ". The query was " + query); Sharpen.Runtime.PrintStackTrace(e); throw new Exception(e); } }
//nothing to do public virtual bool ContainsSentId(string sentId) { try { IConnection conn = SQLConnection.GetConnection(); string query = "Select tokenid from " + tableName + " where sentid=\'" + sentId + "\' limit 1"; IStatement stmt = conn.CreateStatement(); IResultSet rs = stmt.ExecuteQuery(query); bool contains = false; while (rs.Next()) { contains = true; break; } conn.Close(); return(contains); } catch (SQLException e) { throw new Exception(e); } }
/// <summary> /// Note that this is really really slow for ngram > 1 /// TODO: make this fast (if we had been using mysql we could have) /// </summary> public static int GetTotalCount(int ngram) { try { Connect(); IStatement stmt = connection.CreateStatement(); string table = tablenamePrefix + ngram; string q = "select count(*) from " + table + ";"; IResultSet s = stmt.ExecuteQuery(q); if (s.Next()) { return(s.GetInt(1)); } else { throw new Exception("getting table count is not working!"); } } catch (SQLException e) { throw new Exception("getting table count is not working! " + e); } }