method randomValue documentation in bbn\Db
Returns a random value fitting the requested column's type
function($col, $table)
{
$val = null;
if (($tab = $this->modelize($table)) && isset($tab['fields'][$col])) {
foreach ($tab['keys'] as $key => $cfg){
if ($cfg['unique']
&& !empty($cfg['ref_column'])
&& (\count($cfg['columns']) === 1)
&& ($col === $cfg['columns'][0])
) {
return ($num = $this->count($cfg['ref_column'])) ? $this->selectOne(
[
'tables' [$cfg['ref_table']],
'fields' => [$cfg['ref_column']],
'start' => random_int(0, $num - 1)
]
) : null;
}
}
switch ($tab['fields'][$col]['type']){
case 'int':
if (($tab['fields'][$col]['maxlength'] === 1) && !$tab['fields'][$col]['signed']) {
$val = microtime(true) % 2 === 0 ? 1 : 0;
}
else {
$max = 10 ** $tab['fields'][$col]['maxlength'] - 1;
if ($max > mt_getrandmax()) {
$max = mt_getrandmax();
}
if ($tab['fields'][$col]['signed']) {
$max /= 2;
}
$min = $tab['fields'][$col]['signed'] ? -$max : 0;
$val = random_int($min, $max);
}
break;
case 'float':
case 'double':
case 'decimal':
break;
case 'varchar':
break;
case 'text':
break;
case 'date':
break;
case 'datetime':
break;
case 'timestamp':
break;
case 'time':
break;
case 'year':
break;
case 'blob':
break;
case 'binary':
break;
case 'varbinary':
break;
case 'enum':
break;
}
}
return $val;
}
Returns a random value fitting the requested column's type BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions