# File lib/rubyrep/proxy_connection.rb, line 327
    def table_select_query(table, options = {})
      query = "select #{quote_column_list(table)}"
      query << " from #{quote_table_name(table)}"
      query << " where" if [:from, :to, :row_keys].any? {|key| options.include? key}
      first_condition = true
      if options[:from]
        first_condition = false
        matching_condition = options[:exclude_starting_row] ? '>' : '>='
        query << row_condition(table, options[:from], matching_condition)
      end
      if options[:to]
        query << ' and' unless first_condition
        first_condition = false
        query << row_condition(table, options[:to], '<=')
      end
      if options[:row_keys]
        query << ' and' unless first_condition
        if options[:row_keys].empty?
          query << ' false'
        else
          query << ' (' << quote_key_list(table) << ') in ('
          first_key = true
          options[:row_keys].each do |row|
            query << ', ' unless first_key
            first_key = false
            query << '(' << primary_key_names(table).map do |key|
              quote_value(table, key, row[key])
            end.join(', ') << ')'
          end
          query << ')'
        end
      end
      query << " order by #{quote_key_list(table)}"

      query
    end