Beispiel #1
0
function build_tbl_relations(&$relations, $tbl_name, $fields)
{
    //去掉cbm前缀,作为文件名
    $fname = table_no_prefix($tbl_name);
    //得到类名
    $clsname = camel_case($fname);
    foreach ($fields as $name => $type) {
        $param_type = $type;
        $parent_tbl_name = table_no_id($name);
        $var_name = $name;
        $field_name = table_no_prefix($parent_tbl_name);
        if ($name == 'id') {
            continue;
        }
        //该字段是外键(所有的外键ID都是以_id结尾的)
        if ($field_name != $name && $name != 'id') {
            $param_type = camel_case($field_name);
            $var_name = $field_name;
            if (!isset($relations[$parent_tbl_name])) {
                $relations[$parent_tbl_name] = array();
            }
            var_dump($parent_tbl_name . "-->" . $tbl_name);
            $relations[$parent_tbl_name][] = $tbl_name;
        }
    }
    // var_dump($relations);
}
Beispiel #2
0
function table_id($name)
{
    return table_no_prefix($name) . ID_SUBFIX;
}
Beispiel #3
0
function __gen_sql_fkey_py_file($file, $tbl_name, $fields, $relations)
{
    //去掉cbm前缀,作为文件名
    $fname = table_no_prefix($tbl_name);
    //得到类名
    $clsname = camel_case($fname);
    fwrite($file, ENTER . DBL_QUOT . $clsname . DBL_QUOT . ":{" . ENTER);
    //下标序号
    $count = 1;
    //字段变量
    foreach ($fields as $name => $type) {
        $var_name = $name;
        $field_name = table_no_prefix(table_no_id($name));
        $key_type = 0;
        if ($name == 'id') {
            $key_type = 1;
            // 主键
        } else {
            if ($field_name != $name && $name != 'id') {
                $var_name = $field_name;
                $key_type = 2;
                // 外键
            }
        }
        fwrite($file, TAB . DBL_QUOT . $name . DBL_QUOT . ":" . $key_type);
        if ($count < count($fields)) {
            fwrite($file, ',');
        }
        fwrite($file, ENTER);
        $count++;
    }
    fwrite($file, "}");
}
Beispiel #4
0
function gen_entity_source_file($file, $tbl_name, $fields, $relations)
{
    //去掉cbm前缀,作为文件名
    $fname = table_no_prefix($tbl_name);
    //得到类名
    $clsname = camel_case($fname);
    fwrite($file, ENTER . "CString {$clsname}::Table()" . ENTER);
    fwrite($file, "{" . ENTER);
    fwrite($file, TAB . "return " . tchar($tbl_name) . ";" . ENTER);
    fwrite($file, "}" . ENTER);
    fwrite($file, ENTER . "orm::RecordPtr {$clsname}::Create()" . ENTER);
    fwrite($file, "{" . ENTER);
    fwrite($file, TAB . "return orm::RecordPtr(new {$clsname}());" . ENTER);
    fwrite($file, "}" . ENTER);
    //构造函数
    fwrite($file, ENTER . "{$clsname}::{$clsname}() : orm::Record({$clsname}::Table())" . ENTER);
    fwrite($file, "{" . ENTER);
    //初始化成员变量
    foreach ($fields as $name => $type) {
        $param_type = $type;
        $var_name = $name;
        $field_name = table_no_prefix(table_no_id($name));
        if ($name == 'id') {
            continue;
        }
        //该字段是外键(所有的外键ID都是以_id结尾的)
        if ($field_name != $name && $name != 'id') {
            $param_type = camel_case($field_name);
            $var_name = $field_name;
        } else {
            $default_value = type_default($type);
            fwrite($file, TAB . $name . " = " . $default_value . ";" . ENTER);
        }
    }
    //注册属性,并关联成员变量
    foreach ($fields as $name => $type) {
        $param_type = $type;
        $var_name = $name;
        $field_name = table_no_prefix(table_no_id($name));
        if ($name == 'id') {
            continue;
        }
        //该字段是外键(所有的外键ID都是以_id结尾的)
        if ($field_name != $name && $name != 'id') {
            $param_type = camel_case($field_name);
            $var_name = $field_name;
        } else {
            fwrite($file, TAB . "REG_ATTRIB({$name}, {$var_name});" . ENTER);
        }
    }
    //注册属性,并关联成员变量
    foreach ($fields as $name => $type) {
        $param_type = $type;
        $var_name = $name;
        $field_name = table_no_prefix(table_no_id($name));
        if ($name == 'id') {
            continue;
        }
        //该字段是外键(所有的外键ID都是以_id结尾的)
        if ($field_name != $name && $name != 'id') {
            $param_type = camel_case($field_name);
            $var_name = $field_name;
            fwrite($file, TAB . "REG_FOREGIN_KEY({$name}, {$var_name}, &{$param_type}::Create);" . ENTER);
        }
    }
    fwrite($file, "}" . ENTER);
}