Пример #1
0
bool JS4D::DateObjectToVTime( ContextRef inContext, ObjectRef inObject, VTime& outTime, ExceptionRef *outException)
{
	// it's caller responsibility to check inObject is really a Date using ValueIsInstanceOf
	
	// call getTime()
	bool ok = false;
    JSStringRef jsString = JSStringCreateWithUTF8CString( "getTime");
	JSValueRef getTime = JSObjectGetProperty( inContext, inObject, jsString, outException);
	JSObjectRef getTimeFunction = JSValueToObject( inContext, getTime, outException);
    JSStringRelease( jsString);
	JSValueRef result = (getTime != NULL) ? JSObjectCallAsFunction( inContext, getTimeFunction, inObject, 0, NULL, outException) : NULL;
	if (result != NULL)
	{
		// The getTime() method returns the number of milliseconds since midnight of January 1, 1970.
		double r = JSValueToNumber( inContext, result, outException);
		sLONG8 n = (sLONG8) r;
		if (n == r)
		{
			outTime.FromUTCTime( 1970, 1, 1, 0, 0, 0, 0);
			outTime.AddMilliseconds( n);
			ok = true;
		}
		else
		{
			outTime.SetNull( true);
		}
	}
	else
	{
		outTime.SetNull( true);
	}
	return ok;
}
Пример #2
0
//jmo - Ranger ca qq part !
static VTime UnixToXBoxTime(time_t inTime)
{
    VTime res;
    struct tm tm;

    if(gmtime_r(&inTime, &tm)!=NULL)
        //jmo - gmtime month is in the range 0 to 11 but FromUTCTime() wants it in 1 to 12
        // YT - 31-Mar-2011 - tm_year is Year-1900 see struct tm declaration.
        res.FromUTCTime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, 0);

    return res;
}
Пример #3
0
void testMySQLConnectorPreparedStatementWithDateParam()
{
    CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) );

    VJSONObject* params = new VJSONObject();

    params->SetProperty ( "hostname",	MYSQL_HOST );

    params->SetProperty ( "user",		MYSQL_USER );

    params->SetProperty ( "password",	MYSQL_CORRECT_PASSWORD );

    params->SetProperty ( "database",	MYSQL_DATABASE );

    params->SetProperty ( "port",		MYSQL_PORT );

    params->SetProperty ( "ssl",			MYSQL_SSL_FALSE );

    ISQLSession* session = connector->CreateSession ( params );

    ReleaseRefCountable ( &params );

    if ( session != NULL )
    {
        ISQLStatement* statement = session->CreateStatement ( "SELECT * FROM people WHERE date_of_birth = ?" );

        VError error = VE_OK;

        ISQLPreparedStatement* pStmt = statement->CreatePreparedStatement ( error );

        VTime keyDate;

        keyDate.FromUTCTime ( 1984, 8, 11, 0, 0, 0, 0 );

        pStmt->SetNthParameter ( 1, keyDate );

        ISQLResultSet* res = pStmt->Execute ( error );

        if ( error == VE_OK )
        {
            if ( res->IsError() )
            {
                printf ( "an error occured in the execution of the prepared statement!\n" );

                VString msg = res->GetErrorMessage();

                printf ( "error msg = %V\n", &msg );
            }
            else
            {
                while ( !res->IsEOF() )
                {
                    ISQLRow* row = res->RetainNextRow();

                    VValue* idValue = row->GetNthValue ( 1 );

                    VValue* firstNameValue = row->GetNthValue ( 3 );

                    VValue* dateValue = row->GetNthValue ( 5 );

                    VString DbgMsg;

                    DbgMsg.AppendPrintf ( "idValue = %V, firstNameValue = %V, dateValue = %V", idValue, firstNameValue, dateValue );

                    DebugMsg ( "%V", &DbgMsg );

                    ReleaseRefCountable ( &row );
                }
            }

            ReleaseRefCountable ( &res );
        }
        else
        {
            printf ( "an error occured in the execution of the prepared statement!\n" );
        }

        ReleaseRefCountable ( &session );
    }
    else
    {
        printf ( "connection to mysql server failed ..\n" );
    }

    ReleaseRefCountable ( &connector );

}