/// <summary> /// /// </summary> public long Count <ItemType>(MatchExpression matchExpression) where ItemType : class, IDBPersistent { TracerHelper.TraceEntry(typeof(ItemType).Name); string tableName = _tablesTypeNames[typeof(ItemType)]; StringBuilder commandText = new StringBuilder(); commandText.Append("SELECT count(*) FROM " + tableName); if (matchExpression != null && matchExpression.ClauseCount > 0) { commandText.Append(" WHERE "); } _countMutex.WaitOne(); SQLiteCommand command; long result = 0; try { using (SQLiteConnection connection = GenerateConnection()) { using (command = new SQLiteCommand(connection)) { if (matchExpression != null) { matchExpression.SetupCommandParameters(command, commandText); } command.CommandText = commandText.ToString(); connection.Open(); result = (long)command.ExecuteScalar(); } } } finally { _countMutex.ReleaseMutex(); } TracerHelper.TraceExit(); return(result); }
/// <summary> /// /// </summary> public DataSet Select(string[] tablesNames, MatchExpression matchExpression, int?limit) { string names = ""; for (int i = 0; i < tablesNames.Length; i++) { names += tablesNames[i]; if (i != tablesNames.Length - 1) { names += ","; } } TracerHelper.TraceEntry(names); StringBuilder commandText = new StringBuilder(); commandText.Append("SELECT * FROM " + names); if (matchExpression != null && matchExpression.ClauseCount > 0) { commandText.Append(" WHERE "); } _selectMutex.WaitOne(); DataSet set = new DataSet(); try { using (SQLiteConnection connection = GenerateConnection()) { using (SQLiteCommand command = new SQLiteCommand(connection)) { if (matchExpression != null) { matchExpression.SetupCommandParameters(command, commandText); } if (limit.HasValue) { commandText.Append(" LIMIT " + limit.Value); } SQLiteDataAdapter adapter = new SQLiteDataAdapter(); command.CommandText = commandText.ToString(); connection.Open(); adapter.SelectCommand = command; adapter.Fill(set); } } } finally { _selectMutex.ReleaseMutex(); } TracerHelper.TraceExit(); return(set); }