示例#1
0
int UserClient::_CmdIROW( OmniPacket *packet )
{
	int errCode = ERROR_OK;
	char ret[BUFLEN];
	char param[NODELEN];

	PARSE_TAG_INIT( packet->mHeader );
	PARSE_TAG_NEXT( packet->mHeader, param );
	gLog.log("Insert Row timeout %s", param );

	Row row;
	char *buf = packet->mBody;
	char *next;
	char colname[BUFLEN];
	char colvalue[BUFLEN];

	if( mTable == NULL )
	{
		errCode = ERROR_NOT_SELECT_TABLE;
		sprintf( ret, "IROW %lu %d 0\r\n", packet->mTrid, errCode );
		WritePacket( ret, strlen(ret) );
		return errCode;
	}

	while( true )
	{
		bzero( ret, BUFLEN );
		next = strstr( buf, "\r\n" );
		if( next == NULL )
			break;
		if( (next-buf) >= BUFLEN )
			break;
		if( (next-buf) < 0 )
			break;

		sscanf( buf, "%s %s", colname, colvalue );
		gLog.log("[%s] [%s]", colname, colvalue );
		row.AddVal( colname, colvalue );
		buf = next+2;
	}
	mTable->AddRow( &row, atoi(param) );
	Table::Dump();

	sprintf( ret, "IROW %lu %d 0\r\n", packet->mTrid, errCode );
	WritePacket( ret, strlen(ret) );

	return errCode;
}
示例#2
0
int test_std()
{
	Table *tab1, *tab2;
	ColumnInfo colinfo;
	Row row;

	// create table1
	colinfo.Clear();
	colinfo.AddColumn("col1",1,1);
	colinfo.AddColumn("col2",2,2);
	colinfo.AddColumn("col3",4,5);
	tab1 = Table::CreateTable("table1", &colinfo);
	colinfo.Clear();

	row.AddVal("col1", "1");
	row.AddVal("col2", "12");
	row.AddVal("col3", "432");
	tab1->AddRow( &row );
	row.Clear();
	row.AddVal("col1", "2");
	row.AddVal("col2", "23");
	row.AddVal("col3", "234");
	tab1->AddRow( &row );

	// create table2
	colinfo.AddColumn("col2-1",1,2);
	colinfo.AddColumn("col2-2",4,5);
	tab2 = Table::CreateTable("table2", &colinfo);
	colinfo.Clear();

	row.Clear();
	row.AddVal("col2-1", "1");
	row.AddVal("col2-2", "45");
	tab2->AddRow( &row );
	row.Clear();
	row.AddVal("col2-1", "2");
	row.AddVal("col2-2", "56");
	tab2->AddRow( &row );

	Table::Dump();

	// get row
	assert( !strcmp(tab1->GetRow( "1", "col1" ), "1" ) );
	assert( !strcmp(tab1->GetRow( "1", "col2" ), "12" ) );
	assert( !strcmp(tab1->GetRow( "1", "col3" ), "432" ) );
	assert( !strcmp(tab1->GetRow( "2", "col2" ), "23" ) );
	assert( !strcmp(tab1->GetRow( "2", "col3" ), "234" ) );
	assert( !strcmp(tab2->GetRow( "1", "col2-2" ), "45" ) );
	assert( !strcmp(tab2->GetRow( "2", "col2-2" ), "56" ) );
	
	// update row
	tab1->UpdateRow( "1", "col3", "456" );
	assert( !strcmp(tab1->GetRow( "1", "col3" ), "456" ) );

	// del row
	tab1->DelRow( "2" );

	Table::Dump();

	Table::DeleteTable("table1");
	Table::DeleteTable("table2");
	return 0;
}