* Returns -1 if count cannot be found
* Takes same arguments as Database::select()
* @param string $table
- * @param string $vars
+ * @param string $var
* @param string $conds
* @param string $fname
* @param array $options
+ * @param array $join_conds
* @return int
*/
- public function estimateRowCount( $table, $vars = '*', $conds = '',
- $fname = __METHOD__, $options = []
+ public function estimateRowCount( $table, $var = '*', $conds = '',
+ $fname = __METHOD__, $options = [], $join_conds = []
) {
+ $conds = $this->normalizeConditions( $conds, $fname );
+ $column = $this->extractSingleFieldFromList( $var );
+ if ( is_string( $column ) && !in_array( $column, [ '*', '1' ] ) ) {
+ $conds[] = "$column IS NOT NULL";
+ }
+
// http://msdn2.microsoft.com/en-us/library/aa259203.aspx
$options['EXPLAIN'] = true;
$options['FOR COUNT'] = true;
- $res = $this->select( $table, $vars, $conds, $fname, $options );
+ $res = $this->select( $table, $var, $conds, $fname, $options, $join_conds );
$rows = -1;
if ( $res ) {
}
}
- return empty( $result ) ? false : $result;
+ return $result ?: false;
}
/**
return $sql;
}
+ public function buildSubstring( $input, $startPosition, $length = null ) {
+ $this->assertBuildSubstringParams( $startPosition, $length );
+ if ( $length === null ) {
+ /**
+ * MSSQL doesn't allow an empty length parameter, so when we don't want to limit the
+ * length returned use the default maximum size of text.
+ * @see https://docs.microsoft.com/en-us/sql/t-sql/statements/set-textsize-transact-sql
+ */
+ $length = 2147483647;
+ }
+ return 'SUBSTRING(' . implode( ',', [ $input, $startPosition, $length ] ) . ')';
+ }
+
/**
* Returns an associative array for fields that are of type varbinary, binary, or image
* $table can be either a raw table name or passed through tableName() first