Skip to content

Commit a03b2dc

Browse files
committed
Port Functions from CMS
add findInSet() add Rand()
1 parent 1a6e7ca commit a03b2dc

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Sqlsrv/SqlsrvQuery.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,42 @@ public function group($columns)
270270

271271
return $this;
272272
}
273+
274+
/**
275+
* Return correct rand() function for MSSQL.
276+
*
277+
* Ensure that the rand() function is MSSQL compatible.
278+
*
279+
* Usage:
280+
* $query->Rand();
281+
*
282+
* @return string The correct rand function.
283+
*
284+
* @since __DEPLOY_VERSION__
285+
*/
286+
public function Rand()
287+
{
288+
return ' NEWID() ';
289+
}
290+
291+
/**
292+
* Find a value in a varchar used like a set.
293+
*
294+
* Ensure that the value is an integer before passing to the method.
295+
*
296+
* Usage:
297+
* $query->findInSet((int) $parent->id, 'a.assigned_cat_ids')
298+
*
299+
* @param string $value The value to search for.
300+
*
301+
* @param string $set The set of values.
302+
*
303+
* @return string Returns the find_in_set() Mysql translation.
304+
*
305+
* @since __DEPLOY_VERSION__
306+
*/
307+
public function findInSet($value, $set)
308+
{
309+
return "CHARINDEX(',$value,', ',' + $set + ',') > 0";
310+
}
273311
}

0 commit comments

Comments
 (0)