예제 #1
0
        public IEnumerable <DataRecordHelper <T> > SelectData <T>(SqliteConnection connection, String whereClause, Range range = null, Sort sort = null)
        {
            string selectCommand;

            if (String.IsNullOrEmpty(whereClause))
            {
                selectCommand = $"{propertiesAndCommands.SelectCommand()} where {propertiesAndCommands.RangeClause(range)} {propertiesAndCommands.SortClause(sort)};";
            }
            else
            {
                selectCommand = $"{propertiesAndCommands.SelectCommand()} where {whereClause} and {propertiesAndCommands.RangeClause(range)} {propertiesAndCommands.SortClause(sort)};";
            }

            using (var queryCmd = connection.CreateCommand())
            {
                queryCmd.CommandText = selectCommand;

                using (var data = queryCmd.ExecuteReader())
                {
                    var p = new DataRecordHelper <T>(propertiesAndCommands, data);

                    while (data.Read())
                    {
                        yield return(p.IncrementCount());
                    }
                }
            }
        }
예제 #2
0
        public T SelectOne <T>(SqliteConnection connection, string propertyName, Object value, bool assertEmpty = true, bool assertMultiple = true)
        {
            using (var queryCmd = connection.CreateCommand())
            {
                if (value is string || value is Enum)
                {
                    queryCmd.CommandText =
                        $"select * from {propertiesAndCommands.tableName} where {propertyName} = '{value.ToString()}'";
                }
                else
                {
                    queryCmd.CommandText =
                        $"select * from {propertiesAndCommands.tableName} where {propertyName} = {value}";
                }

                using (var data = queryCmd.ExecuteReader())
                {
                    var p = new DataRecordHelper <T>(propertiesAndCommands, data);
                    if (data.Read())
                    {
                        var obj = p.GetObject();

                        if (data.Read() && assertMultiple)
                        {
                            throw new Exception(
                                      $"{propertiesAndCommands.tableName} has more than one entry where {propertyName} equals {value}");
                        }

                        return(obj);
                    }
                    else
                    {
                        if (assertEmpty)
                        {
                            throw new Exception(
                                      $"{propertiesAndCommands.tableName} does not contain entry where {propertyName} equals {value}");
                        }
                        return(default(T));
                    }
                }
            }
        }
예제 #3
0
        public T SelectDataByPrimaryKey <T>(SqliteConnection connection, Object primaryKey)
        {
            string selectCommand = $"{propertiesAndCommands.SelectCommandByPrimaryKey(primaryKey)}";

            using (var queryCmd = connection.CreateCommand())
            {
                queryCmd.CommandText = selectCommand;

                using (var data = queryCmd.ExecuteReader())
                {
                    var p = new DataRecordHelper <T>(propertiesAndCommands, data);

                    if (data.Read())
                    {
                        var z = new DataRecordHelper <T>(propertiesAndCommands, data);
                        return(z.GetObject());
                    }
                }
            }
            return(default(T));
        }