Example #1
0
function rowMatch($orm_name, $class, $property)
{
    $actual_datatypes = getActualDatatypes($orm_name);
    $db_type = getDbType($orm_name);
    if (!isset($_POST[$idx = sprintf('type_%s_%s', $class, $property)])) {
        throw new OrmInputException(sprintf('Must specify a type for %s->%s', $class, $property));
    }
    $datatype = $actual_datatypes[$_POST[$idx]];
    $type = $datatype->type;
    $length = isset($_POST[$idx = sprintf('length_%s_%s', $class, $property)]) && !empty($_POST[$idx]) ? $_POST[$idx] : $datatype->length;
    $default = isset($_POST[$idx = sprintf('default_%s_%s', $class, $property)]) ? $_POST[$idx] : $datatype->default;
    $autoinc = isset($_POST[$idx = sprintf('autoinc_%s_%s', $class, $property)]) && $_POST[$idx] == 'on';
    $allownull = isset($_POST[$idx = sprintf('allownull_%s_%s', $class, $property)]) && $_POST[$idx] == 'on';
    $length = empty($length) ? '' : sprintf(' (%s)', $length);
    $default = empty($default) ? '' : sprintf(' DEFAULT %s', Orm::sqlVar($orm_name, $default, $datatype->cast));
    if ($autoinc) {
        switch ($db_type) {
            case 'Dummy':
            case 'MySQL':
            case 'MySQLi':
                $autoinc = ' AUTO_INCREMENT';
                break;
            case 'SQLite':
                # this page left blank ;) -- SQLite automatically treats integer primary keys as auto_inc
                break;
        }
    } else {
        $autoinc = '';
    }
    if (!$allownull) {
        $allownull = ' NOT NULL';
    } else {
        $allownull = '';
    }
    return (object) array('name' => Orm::propertyToDbName($property), 'type' => $type, 'length' => $length, 'default' => $default, 'allownull' => $allownull, 'autoinc' => $autoinc);
}