<commit_before><commit_msg>Added SQL Server 2005+ library with support for ROW_NUMBER() in limit functionality<commit_after><?php
/**
 * @package Prosper
 */
namespace Prosper;

class MSSql2005Adapter extends BaseAdapter {
  
  /**
	 * Microsoft T-SQL sucks and can't easily do limit offset like every other 
	 * reasonable rdbms, this creates a complex windowing function to do something
	 * that everyone else has built-in.
	 * @param string $sql sql statement
	 * @param int $limit how many records to return
	 * @param int $offset where to start returning 
	 * @return string modified sql statement
	 */
	function limit($sql, $limit, $offset) {
    $pos = strripos(@sql, "select");
    // TODO: Modify to use ORDER BY from $sql
    if ($pos !== false) {
      $pos += 6;
      
      
      $orderpos = strripos($sql, "order by");
      
      $orderpos = strripos($sql, "order by");
      
      if ($orderpos === false) {
        $order = "SELECT 1)) AS row, ";
      } else {
        // I think this accounts for multiple ORDER BY directions, but I could be wrong. It definitely needs tested.
        $order = substr($sql, $orderpos);
      }
      
      $sql = substr($sql, 0, $pos) . " ROW_NUMBER() OVER (ORDER BY (" . $order . substr($sql, $pos);
    }
    
    $sql = "SELECT * FROM (" . $sql . ") WHERE row >= " . $offset . " AND row <= " . ($limit + $offset);
    
    return $sql;
  }
}
?>
{'fraction_non_alphanumeric': 0.13105413105413105, 'fraction_numerical': 0.007834757834757835, 'mean_word_length': 2.5569620253164556, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4491922', 'n_tokens_mistral': 437, 'n_tokens_neox': 410, 'n_words': 155}