Ejemplo n.º 1
0
 fixtureTimestamp() : m_db(NULL)
 {
     nsdatabase::setCheckTablePtr(true);
     m_db = database::create();
     if (!m_db)
         printf("Error database::create()\n");
     short ret = createTestDataBase(m_db);
     if (ret)
     {    
         printf("Error createDataBase\n");
         return;
     }
     m_db->connect(makeUri(PROTOCOL, HOSTNAME, _T("")));
     if (m_db->stat())
     {    
         printf("Error db connect\n");
         return;
     }
     btrVersions vs;
     m_db->getBtrVersion(&vs);
     if (m_db->stat())
     {    
         printf("Error getBtrVersion\n");
         return;
     }
     btrVersion& v = vs.versions[1];
     supportDateTimeTimeStamp =  v.isSupportDateTimeTimeStamp();
     
     ret = createTestTable(m_db, false, supportDateTimeTimeStamp);
     if (ret)
         printf("Error createTable\n");
 }
Ejemplo n.º 2
0
void testNoSchema(database* db)
{
    db->open(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3));
    if (db->stat()==0)
        db->drop();
    
    db->create(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3));
    BOOST_CHECK_MESSAGE(db->stat() == 0, "create stat = " << db->stat());

    db->open(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3));
    BOOST_CHECK_MESSAGE(db->stat() == 0, "open stat = " << db->stat());
    if (db->stat()==0)
    {
        db->drop();
        BOOST_CHECK_MESSAGE(db->stat() == 0, "drop stat = " << db->stat());
    }
}
Ejemplo n.º 3
0
short createTestDataBase(database* db)
{
    if (g_db_created == false)
    {
        db->create(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, BDFNAME));
        if (db->stat() == STATUS_TABLE_EXISTS_ERROR)
        {
            db->open(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, BDFNAME));
            if (db->stat()) return db->stat();
            db->drop();
            db->create(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, BDFNAME));
        }
        if (db->stat()) return db->stat();
        
        g_db_created = true;
    }
    return 0;
}
Ejemplo n.º 4
0
void testUnuseSchema(database* db)
{
    try
    {
        db->close();
        bool ret = db->open(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, _T("")), TYPE_SCHEMA_BDF,TD_OPEN_NORMAL);
        BOOST_CHECK_MESSAGE(ret == true, "db open stat = " << db->stat());
        table_ptr tb = openTable(db, _T("nulltest"), TD_OPEN_NORMAL);
        tb->setKeyNum(0);
        tb->clearBuffer();
        fields& fds = tb->fields();
        fds[(short)0] = 1;
        tb->seek();
        BOOST_CHECK_MESSAGE(tb->stat() == 0, "UnuseSchema seek stat = " << tb->stat());
        for (short i = 1 ;i < (short)fds.size(); ++i)
            BOOST_CHECK_MESSAGE(fds[i].isNull() == true, "UnuseSchema isNull field num = " << i);

        //open second table
        table_ptr tb2 = openTable(db, _T("nulltest"), TD_OPEN_NORMAL);
        BOOST_CHECK_MESSAGE(db->stat() == 0, "UnuseSchema openTable stat = " << db->stat());

        //shared tabledef
        BOOST_CHECK_MESSAGE(db->dbDef()->tableCount() == 1, "tableCount = " << db->dbDef()->tableCount());

        tb2->setKeyNum(0);
        tb2->clearBuffer(table::defaultNull);

        //default values
        fields& fds2 = tb2->fields();
        for (short i = 1 ;i < (short)fds.size(); ++i)
        {
            bool v = true;
            int dv = 0;
            if (i == 0 || i == 5 || i == 6) v = false;
            BOOST_CHECK_MESSAGE(fds2[i].isNull() == v, "defaultValue isNull field num = " << i);
            if (i == 5) dv = -1;
                    
            if (i == 6) dv = -123456;
            BOOST_CHECK_MESSAGE(fds2[i].i() == dv, "defaultValue defaultValue field num = " 
                    << i << " " << fds2[i].i());
        }
    
        fds2[(short)0] = 1;
        tb2->seek();
        BOOST_CHECK_MESSAGE(tb2->stat() == 0, "UnuseSchema seek stat = " << tb2->stat());
        for (short i = 1 ;i < (short)fds2.size(); ++i)
            BOOST_CHECK_MESSAGE(fds2[i].isNull() == true, "UnuseSchema isNull field num = " << i);
    
        db->openTable(_T("abc"));
        BOOST_CHECK_MESSAGE(db->stat() == STATUS_TABLE_NOTOPEN, "openTable stat = " << db->stat());
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("testUnuseSchema Error ! %s\n"), (*getMsg(e)).c_str());
    }
}
Ejemplo n.º 5
0
// This message exists to encapsulate the Dialog State into a SIP message.
// It is created on BS1 to send to BS2, which then uses it as a re-invite.
// So fill it out as a re-invite but leaving the parts based on the BS2 address empty, ie, no via or contact.
// Note that when we send it to BS2 the via and contact are BS1, which BS2 must fix.
// We need to pass the the remote proxy address that we derived from the 'contact' from the peer,
// that was passed in in the initial incoming invite or the response to our outgoing invite.
// We place it in the Refer-To header, and BS2 turns the REFER into an INVITE to that URI.
// This goes in the URI of the header, implying that we cannot send this message to BS2 using normal SIP
// unless we move that to another field, eg, Contact.
SipMessageHandoverRefer::SipMessageHandoverRefer(const SipBase *dialog, string peer)
{
	// The request URI will be the BTS we are sending it to...
	this->smInit();
	this->msmReqMethod = string("REFER");
	this->msmReqUri = makeUri("handover",peer);
	this->msmTo = *dialog->dsRequestToHeader();
	this->msmFrom = *dialog->dsRequestFromHeader();
	this->msmCallId = dialog->callId();
	this->msmCSeqMethod = this->msmReqMethod;	// It is "INVITE".
	// The CSeq num of the are-INVITE follows.
	// RFC3261 14.1: The Cseq for re-INVITE follows same rules for in-dialog requests, namely, CSeq num must be
	// incremented by exactly one.  We do not know if BTS-2 is going to send this this re-INVITE or not,
	// so we send the current CSeqNum without incrementing it and let BTS-2 increment it.
	this->msmCSeqNum = dialog->mLocalCSeq;
	SipParam refer("Refer-To",dialog->dsRemoteURI());	// This is the proxy from the Contact or route header.
	this->msmHeaders.push_back(refer);

	// We need to send the SDP answer, which is the local SDP for MTC or the remote SDP for MOC,
	// but we need to send the peer (remote) RTP port in either case.
	// For the re-invite, you can put nearly anything in here, but you must not just use
	// the identical o= line of the original without at least incrementing the version number.
	SdpInfo sdpRefer, sdpRemote;
	//sdpRefer.sdpInitOffer(dialog);
	sdpRemote.sdpParse(dialog->getSdpRemote());

	// Put the remote SIP server port in the REFER message.  BTS-2 will grab it then substitute its own local port.
	//sdpRefer.sdpRtpPort = sdpRemote.sdpRtpPort;

	sdpRefer.sdpInitRefer(dialog, sdpRemote.sdpRtpPort);

	// TODO: Put the remote session id and version, incrementing the version.  Paul at yate says these should be 0

	//SdpInfo sdpRefer; sdpRefer.sdpParse(dialog->mSdpAnswer);
	//sdpRefer.sdpUsername = dialog->sipLocalusername();

	// Update: This did not work for asterisk either.
	//sdpRefer.sdpUsername = dialog->sipLocalUsername(); // This modification was recommended by Paul for Yate.

	//this->smAddBody(string("application/sdp"),sdpRefer.sdpValue());
	// Try just using the sdpremote verbatim?  Gosh, that worked too.
	this->smAddBody(string("application/sdp"),sdpRefer.sdpValue());

	// The via and contact will be filled in by BS2:
	// this->smAddViaBranch(dialog);
	// this->msmContactValue = dialog->dsRemoteURI();
	// TODO: route set.
}
Ejemplo n.º 6
0
    fixtureStore() : m_db(NULL)
    {
        nsdatabase::setCheckTablePtr(true);
        bool db_created = g_db_created;

        m_db = database::create();
        if (!m_db)
            printf("Error database::create()\n");
        short ret = createTestDataBase(m_db);
        if (ret)
        {    
            printf("Error createDataBase\n");
            return;
        }
        if (!db_created)
            ret = createTestTable(m_db);
        else
        {
             m_db->open(makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, BDFNAME), TYPE_SCHEMA_BDF,TD_OPEN_NORMAL);
             ret = m_db->stat();
        }
        if (ret)
            printf("Error createTable\n");
    }
Ejemplo n.º 7
0
/* Desc of nulltest table timestampNull = true

| Field | Type          | Null | Key | Default              | Extra
+-------+---------------+------+-----+----------------------+-------------------
| id    | int(11)       | NO   | PRI | NULL                 |
| fd1   | int(11)       | YES  | UNI | NULL                 |
| fd2   | int(11)       | YES  |     | NULL                 |
| fd3   | int(11)       | YES  |     | NULL                 |
| fd4   | int(11)       | YES  |     | NULL                 |
| fd5   | int(11)       | YES  |     | -1                   |
| fd6   | varchar(16)   | YES  |     | NULL                 |
| fd7   | varbinary(50) | YES  |     | NULL                 |
| fd8   | timestamp(6)  | YES  |     | NULL                 |
| fd9   | datetime(6)   | YES  |     | NULL                 |
| fd10  | timestamp(6)  | YES  |     | CURRENT_TIMESTAMP(6) | on update CURRENT_TIMESTAMP(6)
| fd11  | datetime(6)   | YES  |     | NULL                 |
+-------+---------------+------+-----+----------------------+-------------------

CREATE TABLE `nulltest` (`id` INT NOT NULL ,`fd1` INT NULL DEFAULT NULL,`fd2` INT NULL DEFAULT NULL,`fd3` INT NULL DEFAULT NULL,`fd4` INT NULL DEFAULT NULL,`fd5` INT NULL DEFAULT '-1',`fd6` VARCHAR(16) binary NULL DEFAULT '-123456',`fd7` VARBINARY(50) NULL DEFAULT NULL,`fd8` TIMESTAMP(6) NULL DEFAULT NULL,`fd9` DATETIME(2) NULL DEFAULT NULL,`fd10` TIMESTAMP(6) NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),`fd11` DATETIME(6) NULL DEFAULT NULL, UNIQUE key0(`id`), UNIQUE key1(`fd1`)) ENGINE=InnoDB default charset=utf8
*/
short createTestTable(database* db, bool timestampNull = true, bool supportDateTimeTimeStamp = true)
{
    try
    {
        openDatabase(db, makeUri(PROTOCOL, HOSTNAME, DBNAMEV3, BDFNAME), TYPE_SCHEMA_BDF,TD_OPEN_NORMAL);
        dbdef* def = db->dbDef();
        short tableid = 1;
        db->dropTable(_T("nulltest"));
        def->deleteTable(tableid);
        
        short fieldnum = 0;
        insertTable(def, tableid,  _T("nulltest"), g_td_charsetIndex);

        insertField(def, tableid, fieldnum, _T("id"), ft_integer, 4);
        fielddef* fd = insertField(def, tableid, ++fieldnum, _T("fd1"), ft_integer, 4);
        fd->setNullable(true);
        //fd->nullbit = 100;
        //fd->nullbytes = 30;

        fd = insertField(def, tableid, ++fieldnum, _T("fd2"), ft_integer, 4);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd3"), ft_integer, 4);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd4"), ft_integer, 4);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd5"), ft_integer, 4);
        fd->setNullable(timestampNull, false);
        fd->setDefaultValue(-1LL);
        fd = insertField(def, tableid, ++fieldnum, _T("fd6"), ft_myvarchar, 49);
        fd->setNullable(true, false);
        fd->setDefaultValue(_T("-123456"));
        //fd->setDefaultValue(_T("漢字"));
        fd = insertField(def, tableid, ++fieldnum, _T("fd7"), ft_myvarbinary, 51);
        fd->setNullable(true);
        fd = insertField(def, tableid, ++fieldnum, _T("fd8"), ft_mytimestamp, 7);
        fd->setNullable(timestampNull);
        fd->decimals = 6;

        fd = insertField(def, tableid, ++fieldnum, _T("fd9"), ft_mydatetime, 6);
        fd->setNullable(true);
        fd->decimals = 2;

        fd = insertField(def, tableid, ++fieldnum, _T("fd10"), ft_mytimestamp, 7);
        fd->setNullable(true);
        fd->decimals = 6;
        if (timestampNull == false && supportDateTimeTimeStamp)
        {
            fd->setDefaultValue(DFV_TIMESTAMP_DEFAULT);
            fd->setTimeStampOnUpdate(true);
        }

        fd = insertField(def, tableid, ++fieldnum, _T("fd11"), ft_mydatetime, 8);
        fd->setNullable(timestampNull);
        fd->decimals = 6;
        if (timestampNull == false && supportDateTimeTimeStamp)
            fd->setTimeStampOnUpdate(true);

        fd = insertField(def, tableid, ++fieldnum, _T("fd12"), ft_myyear, 1);
        fd->setNullable(true);

        keydef* kd = insertKey(def, tableid, 0);
        kd->segments[0].fieldNum = 0;
        kd->segments[0].flags.bit8 = 1; // extended key type
        kd->segments[0].flags.bit1 = 1; // changeable
        kd->segmentCount = 1;
        
        kd = insertKey(def, tableid, 1);
        kd->segments[0].fieldNum = 1;
        kd->segments[0].flags.bit8 = 1; // extended key type
        kd->segments[0].flags.bit1 = 1; // changeable
        kd->segmentCount = 1;
        tabledef* td = def->tableDefs(tableid);
        td->primaryKeyNum = 0;
        updateTableDef(def, tableid);
        return 0;
   
    }
    catch (bzs::rtl::exception& e)
    {
        _tprintf(_T("Error! %s\n"), (*getMsg(e)).c_str());
    }
    return 1;
}