2015-08-14 240 views

回答

1

下面的代码片段来自伟大的oracle.dart库,用于连接Oracle数据库。它从结果集中读取Oracle日期并使用6个构造函数参数创建一个新的Dart DateTime对象。

void OracleResultSet_getDate(Dart_NativeArguments args) { 
    Dart_EnterScope(); 

    auto rs = getThis<occi::ResultSet>(args); 
    int64_t index = getDartArg<int64_t>(args, 1); 

    occi::Date date; 
    try { 
    date = rs->getDate(index); 
    } CATCH_SQL_EXCEPTION 

    int year; 
    unsigned int month; 
    unsigned int day; 
    unsigned int hour; 
    unsigned int min; 
    unsigned int seconds; 
    date.getDate(year, month, day, hour, min, seconds); 

    std::vector<Dart_Handle> dargs; 
    dargs.push_back(Dart_NewInteger(year)); 
    dargs.push_back(Dart_NewInteger(month)); 
    dargs.push_back(Dart_NewInteger(day)); 
    dargs.push_back(Dart_NewInteger(hour)); 
    dargs.push_back(Dart_NewInteger(min)); 
    dargs.push_back(Dart_NewInteger(seconds)); 

    Dart_Handle lib = GetDartLibrary("dart:core"); 
    Dart_Handle type = HandleError(Dart_GetType(lib, Dart_NewStringFromCString("DateTime"), 0, NULL)); 
    Dart_Handle obj = HandleError(Dart_New(type, Dart_Null(), 6, &dargs[0])); 

    Dart_SetReturnValue(args, obj); 
    Dart_ExitScope(); 
} 
+0

很确定只适用于可选的位置参数,而不是命名参数。 –