Пример #1
0
/*
    删除表中的一个数据
*/
bool userDatabase::DeleteData(){
    int Size = mySql.sqlWord.size();
    if(mySql.sqlWord[1] == "from"){
        string name = mySql.sqlWord[2];
        int tableid = FindTable(name);
        if(tableid != -1){
            Condition selectValue,whereValue;
            if(canRead(4) && mySql.sqlWord[3]  == "where"){
                    string na,sy,va;
                    for(int pos = 4;pos < Size;pos++){
                        if(canRead(pos))
                            na = mySql.sqlWord[pos++];
                        if(canRead(pos))
                            sy = mySql.sqlWord[pos++];
                        if(canRead(pos))
                            va = mySql.sqlWord[pos++];
                        //cout << na << " " << sy << " " << va << endl;
                        if(!whereValue.addValue(na,sy,va)){
                            return false;
                        }
                    }
            }
            if(myTable[tableid].findCondition(3,selectValue,whereValue))
                return true;
            else
                return false;
        }
        else
            kLine::NotFindTable(name);
    }
    return false;
}
Пример #2
0
bool CAeonEngine::GetKeyRange (const SArchonMessage &Msg, const CString &sTable, int iCount)

//	GetKeyRange
//
//	Processes a getKeyRange message

	{
	//	If the table doesn't exist, then we can't continue

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
		return false;
		}

	//	Create an iterator

	CDatum dResult;
	CString sError;
	if (!pTable->GetKeyRange(iCount, &dResult, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return false;
		}

	//	Reply

	SendMessageReply(MSG_AEON_RESULT_KEYS, dResult, Msg);
	return true;
	}
Пример #3
0
// Load the string from the table
char *GetTableStr(char *name)
{
	TABLE *t;
	// Validate arguments
	if (name == NULL)
	{
		return "";
	}

#ifdef	OS_WIN32
	if (StrCmpi(name, "DEFAULT_FONT") == 0)
	{
		if (_II("LANG") == 2)
		{
			UINT os_type = GetOsType();
			if (OS_IS_WINDOWS_9X(os_type) ||
				GET_KETA(os_type, 100) <= 4)
			{
				// Use the SimSun font in Windows 9x, Windows NT 4.0, Windows 2000, Windows XP, and Windows Server 2003
				return "SimSun";
			}
		}
	}
#endif	// OS_WIN32

	// Search
	t = FindTable(name);
	if (t == NULL)
	{
		//Debug("%s: ANSI STRING NOT FOUND\n", name);
		return "";
	}

	return t->str;
}
Пример #4
0
void CAeonEngine::MsgMutate (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)

//	MsgMutate
//
//	Aeon.mutate {tableName} {rowPath} {data} {mutationDesc}

	{
	AEONERR error;

	const CString &sTable = Msg.dPayload.GetElement(0);
	CDatum dRowPath = Msg.dPayload.GetElement(1);
	CDatum dData = Msg.dPayload.GetElement(2);
	CDatum dMutateDesc = Msg.dPayload.GetElement(3);

	//	Make sure we are allowed access to this table

	if (!ValidateTableAccess(Msg, pSecurityCtx, sTable))
		return;

	//	If the table doesn't exist, then we can't continue

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
		return;
		}

	//	Parse the path
	//
	//	NOTE: We don't need to validate that this is a valid path for create
	//	because we do that later inside Mutate. [Because Mutate accepts a nil
	//	path when generating a unique key.]

	CString sError;
	CRowKey Path;
	if (!pTable->ParseDimensionPath(NULL_STR, dRowPath, &Path, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Mutate

	CDatum dResult;
	if (error = pTable->Mutate(Path, dData, dMutateDesc, &dResult, &sError))
		{
		if (error == AEONERR_OUT_OF_DATE)
			SendMessageReplyError(MSG_ERROR_OUT_OF_DATE, sError, Msg);
		else
			SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Done

	SendMessageReply(MSG_REPLY_DATA, dResult, Msg);
	}
Пример #5
0
/*! \brief Returns how much room is required to draw a string in the font.
	\param inText The string to be examined.
	\param fromOffset The offset in the string where to begin the examination.
	\param lenght The amount of bytes to be examined.
	\param inStyle The font.
	\return The space (in pixels) required to draw the given string.
*/
float
WidthBuffer::StringWidth(const char *inText, int32 fromOffset,
	int32 length, const BFont *inStyle)
{
	if (inText == NULL || length == 0)
		return 0;

	BAutolock _(fLock);

	int32 index = 0;
	if (!FindTable(inStyle, &index))
		index = InsertTable(inStyle);

	char *text = NULL;
	int32 numChars = 0;
	int32 textLen = 0;

	char *sourceText = (char *)inText + fromOffset;
	const float fontSize = inStyle->Size();
	float stringWidth = 0;
	for (int32 charLen = 0;
			sourceText < inText + length;
			sourceText += charLen) {
		charLen = UTF8NextCharLen(sourceText);

		// End of string, bail out
		if (charLen <= 0)
			break;

		// Some magic, to uniquely identify this charachter
		const uint32 value = CharToCode(sourceText, charLen);

		float escapement;
		if (GetEscapement(value, index, &escapement)) {
			// Well, we've got a match for this charachter
			stringWidth += escapement;
		} else {
			// Store this charachter into an array, which we'll
			// pass to HashEscapements() later
			int32 offset = textLen;
			textLen += charLen;
			numChars++;
			text = (char *)realloc(text, textLen);
			for (int32 x = 0; x < charLen; x++)
				text[offset + x] = sourceText[x];
		}
	}

	if (text != NULL) {
		// We've found some charachters which aren't yet in the hash table.
		// Get their width via HashEscapements()
		stringWidth += HashEscapements(text, numChars, textLen, index, inStyle);
		free(text);
	}

	return stringWidth * fontSize;
}
Пример #6
0
/*
    输出用户所拥有表的所有信息
*/
bool userDatabase::InputTable(string name){
    int tableid = FindTable(name);
    if(tableid == -1){
        kLine::NotFindTable(name);
        return false;
    }
    myTable[tableid].TableView();
    return true;
}
Пример #7
0
Status InitMeasurementTable(MeasurementTable* measurementTable, const char* name, byte columns, byte rows)
{
    Status status = FindTable(name, &(measurementTable->table));
    if (status != OK)
    {
        status = CreateTable(name, columns, rows, &(measurementTable->table));
    }
    measurementTable->name = name;
    return status;
}
Пример #8
0
void CAeonEngine::MsgFileDirectory (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)

//	MsgFileDirectory
//
//	Aeon.fileDirectory {filePath} {requestedFields} {options}

	{
	CString sError;

	//	Get the filePath

	CString sTable;
	CString sFilePath;
	if (!CAeonTable::ParseFilePath(Msg.dPayload.GetElement(0), &sTable, &sFilePath, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_PARSING_FILE_PATH, sError), Msg);
		return;
		}

	//	Make sure we are allowed access to this table

	if (!ValidateTableAccess(Msg, pSecurityCtx, sTable))
		return;

	//	Convert the filepath to a key

	CString sDirKey = CRowKey::FilePathToKey(sFilePath);

	//	Get the table

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
		return;
		}

	//	Get the set of requested fields and options

	CDatum dRequestedFields = Msg.dPayload.GetElement(1);
	CDatum dOptions = Msg.dPayload.GetElement(2);

	//	Do it

	CDatum dResult;
	if (!pTable->FileDirectory(sDirKey, dRequestedFields, dOptions, &dResult, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Reply

	SendMessageReply(MSG_REPLY_DATA, dResult, Msg);
	}
Пример #9
0
void CAeonEngine::MsgInsertNew (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)

//	MsgInsertNew
//
//	Aeon.insertNew {tableName} {rowPath} {data}
//
//	{rowPath} is an array with as many elements as the table dimensions

	{
	AEONERR error;

	const CString &sTable = Msg.dPayload.GetElement(0);
	CDatum dRowPath = Msg.dPayload.GetElement(1);
	CDatum dData = Msg.dPayload.GetElement(2);

	//	Make sure we are allowed access to this table

	if (!ValidateTableAccess(Msg, pSecurityCtx, sTable))
		return;

	//	If the table doesn't exist, then we can't continue

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
		return;
		}

	//	Parse the path

	CString sError;
	CRowKey Path;
	if (!pTable->ParseDimensionPathForCreate(dRowPath, &Path, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Insert

	if (error = pTable->Insert(Path, dData, true, &sError))
		{
		if (error == AEONERR_ALREADY_EXISTS)
			SendMessageReplyError(MSG_ERROR_ALREADY_EXISTS, sError, Msg);
		else
			SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Done

	SendMessageReply(MSG_OK, CDatum(), Msg);
	}
Пример #10
0
// determines language system from string s (with length l)
// FIXME: implement for relevant scripts
static const UINT8* GetLanguageSystem(const UINT8* ScriptList, const UINT8* end,
									  const UINT32 s, const UINT32 l)
{
	if (!ScriptList)
		return 0;

	// find out script and language system
	UINT32 scriptTag = 0, languageSystemTag = 0;
	// FIXME: determine scripts and language systems here (from s and l)

	if (!scriptTag)
		return 0;

	const UINT8* Script = FindTable(ScriptList, end, scriptTag);
	if (!Script)
		return 0;


#if 0
	// DEBUG: print language systems for current script
	fprintf(stderr, "listing language systems for script\n");
	UINT16 numLangSys = MDF_GetU16(Script+2);
	for (UINT32 i = 0; i < numLangSys; ++i)
		fprintf(stderr, "* %c%c%c%c\n",
				Script + 4 + 6*i + 0,
				Script + 4 + 6*i + 1,
				Script + 4 + 6*i + 2,
				Script + 4 + 6*i + 3);
#endif // 0


	const UINT8* LanguageSystem = FindTable(Script, end, languageSystemTag, 2);
	if (!LanguageSystem) // fall back to default
	{
		LanguageSystem = GetTable(Script, 0);
		if (LanguageSystem == Script)
			return 0;
	}

	return LanguageSystem;
}
Пример #11
0
/*
    创建索引
*/
bool userDatabase::CreateIndex(){
    kIndex newindex;
    newindex.name = mySql.sqlWord[3];
    int Size = mySql.sqlWord.size();
    if(FindIndex(newindex.name) != -1){
        cout << "[Error] The index has existing!" << endl;
        return false;
    }
    if(mySql.sqlWord[1] == "unique") newindex.itype = 1;
    if(mySql.sqlWord[1] == "cluster")newindex.itype = 2;

    if(newindex.itype == 0){
        cout << "[Error] The type of the index is wrong!" << endl;
        return false;
    }

    newindex.tablename = mySql.sqlWord[5];
    int tid = FindTable(newindex.tablename);
    if(tid == -1){
        kLine::NotFindTable(newindex.tablename);
        return false;
    }
    for(int pos = 6; pos < Size; pos++){
        string column = mySql.sqlWord[pos];
        if(column == "," || column == "and")
            continue;
        int cid = myTable[tid].findColumn(column);
        if(cid == -1){
            kLine::NotFindColumn(column);
            return false;
        }
        newindex.column.push_back(column);
        if(pos + 1 < Size){
            if(mySql.sqlWord[pos + 1] == "asc"){
                newindex.type.push_back(1);
                pos ++;
            }
            if(mySql.sqlWord[pos + 1] == "desc"){
                newindex.type.push_back(2);
                pos ++;
            }
            else{
                newindex.type.push_back(1);
            }
        }
        else
            newindex.type.push_back(1);
    }
    myIndex.push_back(newindex);
    cout << "[OK] Create index success!" << endl;
    InputIndex(newindex.name);
    return true;
}
Пример #12
0
void CAeonEngine::MsgFileGetDesc (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)

//	MsgFileGetDesc
//
//	Aeon.fileGetDesc {filePath}

	{
	CString sError;

	//	Get the filePath

	CString sTable;
	CString sFilePath;
	if (!CAeonTable::ParseFilePath(Msg.dPayload.GetElement(0), &sTable, &sFilePath, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_PARSING_FILE_PATH, sError), Msg);
		return;
		}

	//	Make sure we are allowed access to this table

	if (!ValidateTableAccess(Msg, pSecurityCtx, sTable))
		return;

	//	Get the table

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
		return;
		}

	//	Get the descriptor

	CDatum dFileDesc;
	if (!pTable->GetFileDesc(sFilePath, &dFileDesc, &sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Prepare the descriptor for return

	CDatum dNewFileDesc = CAeonTable::PrepareFileDesc(sTable, sFilePath, dFileDesc);

	//	Done

	SendMessageReply(MSG_REPLY_DATA, dNewFileDesc, Msg);
	}
Пример #13
0
void EventDispatcher::DispatchEvent(InotifyEvent& rEvt)
{
    if (m_pIn == NULL)
        return;

    InotifyWatch* pW = rEvt.GetWatch();
    if (pW == NULL)
        return;

    UserTable* pT = FindTable(pW);
    if (pT == NULL)
        return;

    pT->OnEvent(rEvt);
}
Пример #14
0
const ALib::XMLElement *  ReadXMLCommand :: FindTable(
												const ALib::XMLElement * e ) {
	if ( e->Name() == "table" ) {
		return e;
	}

	for ( unsigned int i = 0; i < e->ChildCount(); i++ ) {
		const ALib::XMLElement * ce = e->ChildElement( i );
		const ALib::XMLElement * t = FindTable( ce );
		if ( t ) {
			return t;
		}
	}
	return 0;
}
Пример #15
0
void ReadXMLCommand :: TableToCSV( const ALib::XMLElement * e,
										IOManager & io,
										unsigned int idx  ) {

	const ALib::XMLElement * table = FindTable( e );
	if ( table == 0 ) {
		CSVTHROW( "No XML table found in " <<  io.InFileName( idx ) );
	}

	for ( unsigned int i = 0; i < table->ChildCount(); i++ ) {
		const ALib::XMLElement * ce = table->ChildElement( i );
		if ( ce && ce->Name() == "tr" ) {
			WriteRow( ce, io );
		}
	}

}
Пример #16
0
bool CAeonEngine::GetViewStatus (const CString &sTable, DWORD dwViewID, bool *retbUpToDate, CString *retsError)

//	GetViewStatus
//
//	Returns the status of the given view

	{
	CSmartLock Lock(m_cs);

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		*retsError = strPattern(STR_ERROR_UNKNOWN_TABLE, sTable);
		return false;
		}

	return pTable->GetViewStatus(dwViewID, retbUpToDate, retsError);
	}
Пример #17
0
/*
    修改一个表的数据
*/
bool userDatabase::UpdateTable(){
    string name = mySql.sqlWord[1];
    int tableid = FindTable(name);
    int Size = mySql.sqlWord.size();
    if(tableid == -1){
        kLine::NotFindTable(name);
        return false;
    }
    Condition setValue,whereValue;
    int pos = 3;
    string na,sy,va;
    for(;pos < Size;pos++){
        if(canRead(pos))
            na = mySql.sqlWord[pos++];
        if(canRead(pos))
            sy = mySql.sqlWord[pos++];
        if(canRead(pos))
            va = mySql.sqlWord[pos++];
        if(!setValue.addValue(na,sy,va)){
            return false;
        }
        if(canRead(pos) && mySql.sqlWord[pos] == "where"){
            pos ++;
            break;
        }
    }

    for(;pos < Size;pos++){
        if(canRead(pos))
            na = mySql.sqlWord[pos++];
        if(canRead(pos))
            sy = mySql.sqlWord[pos++];
        if(canRead(pos))
            va = mySql.sqlWord[pos++];
        if(!whereValue.addValue(na,sy,va)){
            return false;
        }
    }
    if(myTable[tableid].findCondition(2,setValue,whereValue))
        return true;
    else
        return false;
}
Пример #18
0
// Load a Unicode string from the table
wchar_t *GetTableUniStr(char *name)
{
	TABLE *t;
	// Validate arguments
	if (name == NULL)
	{
//		Debug("%s: ************\n", name);
		return L"";
	}

	// Search
	t = FindTable(name);
	if (t == NULL)
	{
		//Debug("%s: UNICODE STRING NOT FOUND\n", name);
		return L"";
	}

	return t->unistr;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *tableName - 
//			maxentries - 
// Output : TABLEID
//-----------------------------------------------------------------------------
INetworkStringTable *CNetworkStringTableContainer::CreateStringTableEx( const char *tableName, int maxentries, int userdatafixedsize /*= 0*/, int userdatanetworkbits /*= 0*/, bool bIsFilenames /*= false */ )
{
	if ( !m_bAllowCreation )
	{
		Sys_Error( "Tried to create string table '%s' at wrong time\n", tableName );
		return NULL;
	}

	CNetworkStringTable *pTable = (CNetworkStringTable*) FindTable( tableName );

	if ( pTable != NULL )
	{
		Sys_Error( "Tried to create string table '%s' twice\n", tableName );
		return NULL;
	}

	if ( m_Tables.Count() >= MAX_TABLES )
	{
		Sys_Error( "Only %i string tables allowed, can't create'%s'", MAX_TABLES, tableName);
		return NULL;
	}

	TABLEID id = m_Tables.Count();

	pTable = new CNetworkStringTable( id, tableName, maxentries, userdatafixedsize, userdatanetworkbits, bIsFilenames );

	Assert( pTable );

#ifndef SHARED_NET_STRING_TABLES
	if ( m_bEnableRollback )
	{
		pTable->EnableRollback();
	}
#endif

	pTable->SetTick( m_nTickCount );

	m_Tables.AddToTail( pTable );

	return pTable;
}
bool CNetworkStringTableContainer::ReadStringTables( CUtlBuffer& buf )
{
	int numTables = buf.GetInt();
	for ( int i = 0 ; i < numTables; i++ )
	{
		char tablename[ 256 ];
		buf.GetString( tablename, sizeof( tablename ) );

		// Find this table by name
		CNetworkStringTable *table = (CNetworkStringTable*)FindTable( tablename );
		Assert( table );

		// Now read the data for the table
		if ( !table->ReadStringTable( buf ) )
		{
			Host_Error( "Error reading string table %s\n", tablename );
		}

	}
	return true;
}
Пример #21
0
void CAeonEngine::MsgRecoverTableTest (const SArchonMessage &Msg, const CHexeSecurityCtx *pSecurityCtx)

//	MsgRecoverTableTest
//
//	Aeon.recoverTableTest {tableName}

	{
	//	This is an admin operation

	if (!ValidateAdminAccess(Msg, pSecurityCtx))
		return;

	//	Get the table

	const CString &sTable = Msg.dPayload.GetElement(0);

	//	If the table doesn't exist, then we can't continue

	CAeonTable *pTable;
	if (!FindTable(sTable, &pTable))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, strPattern(STR_ERROR_UNKNOWN_TABLE, sTable), Msg);
		return;
		}

	//	Recover

	CString sError;
	if (!pTable->RecoverTableRows(&sError))
		{
		SendMessageReplyError(MSG_ERROR_UNABLE_TO_COMPLY, sError, Msg);
		return;
		}

	//	Done

	SendMessageReply(MSG_OK, CDatum(), Msg);
	}
Пример #22
0
bool userDatabase::InputView(string name){
    int viewid = FindView(name);
    if(viewid == -1){
        kLine::NotFindView(name);
        return false;
    }
    else{
        int tableid = FindTable(myView[viewid].tablename);
        if(tableid == -1){
            cout << "[Error] Can't find the table for the view" << endl;
            return false;
        }
        if(myTable[tableid].findCondition(4,myView[viewid].selectColumn,myView[viewid].whereRow)){
            return true;
        }
        else{
            myView.erase(myView.begin() + viewid);
            cout << "[Warning] The error view has been deleted" << endl;
            return false;
        }
    }
    return false;
}
Пример #23
0
/*
    删除一个表
*/
bool userDatabase::DeleteTable(){
    if(canRead(2)){
        string name = mySql.sqlWord[2];
        int tableid = FindTable(name);
        if(tableid == -1){
            kLine::NotFindTable(name);
            return false;
        }
        myTable.erase(myTable.begin() + tableid);
        //---------------------------------------
        char path[256];
        strcpy(path,"table\\");
        int j = strlen(path);
        for(int i = 0; i < (int)name.size(); i++){
            path[j++] = name[i];
        }
        path[j] = '\0';
        //---------------------------------------
        remove(path);
        cout << "[OK] Delete the table [" << name << "] success." << endl;
    }
    return true;
}
Пример #24
0
/*
    表内容的查找
*/
bool userDatabase::SelectTable(){
    int Size = mySql.sqlWord.size();
    int from = 0,pos = 1;
    int tableid;
    Condition selectValue,whereValue;
    string name = "";
    for(;from < Size; from ++){
        if(mySql.sqlWord[from] == "from"){
            from ++;
            break;
        }
    }
    if(canRead(from)){
        name = mySql.sqlWord[from];
    }
    tableid = FindTable(name);
    if(tableid == -1){
        kLine::NotFindTable(name);
        return false;
    }
    int ok = 0;
    for(;pos < Size; pos ++){
        if(mySql.sqlWord[pos] == "from") ok = 1;
        if(!ok && mySql.sqlWord[pos] != ","){
            selectValue.addValue(string(mySql.sqlWord[pos]),string("="),string("NULL"));
        }
        if(mySql.sqlWord[pos] == "order" || mySql.sqlWord[pos] == "group" || mySql.sqlWord[pos] == "having"){
            break;
        }
        if(mySql.sqlWord[pos] == "where"){
            pos ++;
            break;
        }
    }
    string na,sy,va;
    for(;pos < Size;pos++){
        if(canRead(pos) && (mySql.sqlWord[pos] == "," || mySql.sqlWord[pos] == "and")){
            continue;
        }
        if(canRead(pos)){
            if(canRead(pos + 2) && mySql.sqlWord[pos] == "order" && mySql.sqlWord[pos + 1] == "by"){
                selectValue.orderColumn = mySql.sqlWord[pos + 2];
                if(canRead(pos + 3) && mySql.sqlWord[pos + 3] == "asc"){
                    selectValue.order = 1;
                    //cout << "ASC ";
                    //cout << selectValue.orderColumn << endl;
                    pos += 3;
                }
                else if(canRead(pos + 3) && mySql.sqlWord[pos + 3] == "desc"){
                    selectValue.order = 2;
                    //cout << "DESC ";
                    //cout << selectValue.orderColumn << endl;
                    pos += 3;
                }
                else{
                    selectValue.order = 1;
                    //cout << "ASC ";
                    //cout << selectValue.orderColumn << endl;
                    pos += 2;
                }
                continue;
            }
            if(canRead(pos + 2) && mySql.sqlWord[pos] == "group" && mySql.sqlWord[pos + 1] == "by"){
                //cout << mySql.sqlWord[pos + 2] << endl;
                pos += 2;
                continue;
            }
        }
        if(canRead(pos))
            na = mySql.sqlWord[pos++];
        if(canRead(pos))
            sy = mySql.sqlWord[pos++];
        if(canRead(pos))
            va = mySql.sqlWord[pos];
        //cout << na << " " << sy << " " << va << endl;
        if(!whereValue.addValue(na,sy,va)){
            return false;
        }
    }
    if(myTable[tableid].findCondition(1,selectValue,whereValue))
        return true;
    return true;
}
Пример #25
0
bool userDatabase::GrantToUser(){
    int pos = 1;
    int type = JudgeGrant(pos);
    int Size = mySql.sqlWord.size();
    string tablename;
    string username;
    int step = 0;
    //cout << type << endl;
    if(type == -1){
        return false;
    }
    for(;pos < Size; pos++){
        if(mySql.sqlWord[pos] == "on"){
            pos ++;
            break;
        }
    }
    for(;pos < Size;pos ++){
        if(step == 0){
            tablename = mySql.sqlWord[pos];
            step ++;
        }
        else if(step == 1 && mySql.sqlWord[pos] == "to"){
            step ++;
        }
        else if(step == 2){
            username = mySql.sqlWord[pos];
            step ++;
            break;
        }
    }

    if(step == 3){
        int id = FindTable(tablename);
        if(id == -1){
            kLine::NotFindTable(tablename);
            return false;
        }
        //先判断自己是否有权限
        if(type == 1){
            if(!myTable[id].can_read){
                cout << "[Warning] You do not have permission!" << endl;
                return false;
            }
            userDatabase user(username);
            int tid = user.FindTable(tablename);
            if(tid == -1){
                kTable newtable;
                newtable.name = tablename;
                save.getTable(newtable);
                user.myTable.push_back(newtable);
                newtable.can_read  = true;
                newtable.can_write = false;
            }
            else{
                user.myTable[tid].can_read = true;
            }
            cout << "[OK] User [" << username  << "] has the permission of [" << tablename << "] (select)" << endl;
            return true;
        }
        if(type == 2){
            if(!myTable[id].can_read || !myTable[id].can_write){
                cout << "[Warning] You do not have permission!" << endl;
                return false;
            }
            userDatabase user(username);
            int tid = user.FindTable(tablename);
            if(tid == -1){
                kTable newtable;
                newtable.name = tablename;
                save.getTable(newtable);
                user.myTable.push_back(newtable);
                newtable.can_read  = true;
                newtable.can_write = true;
            }
            else{
                user.myTable[tid].can_read  = true;
                user.myTable[tid].can_write = true;
            }
            cout << "[OK] User [" << username  << "] has the permission of [" << tablename << "] (all)" << endl;
            return true;
        }
    }
    return false;
}
Пример #26
0
bool userDatabase::CreateView(){
    string viewname = mySql.sqlWord[2];
    if(FindView(viewname) != -1){
        cout << "[Error] View is existing!" << endl;
        return false;
    }
    int Size = mySql.sqlWord.size();
    if(Size >= 4 && mySql.sqlWord[3] == "as"){
        int from = 0,pos = 1;
        int tableid;
        kView view;
        view.viewname = viewname;
        string name = "";
        for(;from < Size; from ++){
            if(mySql.sqlWord[from] == "from"){
                from ++;
                break;
            }
        }
        if(canRead(from)){
            name = mySql.sqlWord[from];
        }
        tableid = FindTable(name);
        if(tableid == -1){
            kLine::NotFindTable(name);
            return false;
        }
        //视图属于的表名字
        view.tablename = name;
        int ok = 0;
        for(;pos < Size;pos++)
            if(mySql.sqlWord[pos] == "select"){
                pos ++;
                break;
            }
        for(;pos < Size; pos ++){
            if(mySql.sqlWord[pos] == "from") ok = 1;
            if(!ok && mySql.sqlWord[pos] != ","){
                view.selectColumn.addValue(string(mySql.sqlWord[pos]),string("="),string("NULL"));
            }
            if(mySql.sqlWord[pos] == "where"){
                pos ++;
                break;
            }
        }
        string na,sy,va;
        for(;pos < Size;pos++){
            if(canRead(pos))
                na = mySql.sqlWord[pos++];
            if(canRead(pos))
                sy = mySql.sqlWord[pos++];
            if(canRead(pos))
                va = mySql.sqlWord[pos++];
            if(!view.whereRow.addValue(na,sy,va)){
                return false;
            }
        }
        myView.push_back(view);
        InputView(viewname);
        return true;
    }
    return false;
}
Пример #27
0
/*
如:
    CREATE TABLE student(
        name char(20),
        id int,
        class char(10),
    );
*/
bool userDatabase::CreateTable(){
    kTable newTable;
    int Size = mySql.sqlWord.size();
    if(Size < 3)
        return false;
    newTable.name = mySql.sqlWord[2];
    int i = 3;
    string name;
    int type,unit,iskey;
    // if(i < Size)
    for(; i < Size; i++){
        type = -1;
        unit = 0;
        iskey = 0;
        //提取姓名
        name = mySql.sqlWord[i];
        i ++;
        //提取种类
        if(canRead(i))
            type = JudgeType(i);
        if(type == -1) return false;
        i++;
        //判断单位
        if(canRead(i) && mySql.sqlWord[i] != ","){
            if(type == 2){
                unit = JudgeUnit(i);
                i++;
            }
            if(canRead(i) && mySql.sqlWord[i] != ","){
                iskey = JudgeKey(i);
            }
        }
        if(!newTable.addColumn(name,type,unit,iskey)){
            cout << "[Error] The table have the same column!" << endl;
            return false;
        }
        //判断主键
    }
    Size = newTable.columnName.size();
    if(FindTable(newTable.name) != -1){
        cout << "[Error] Table is existing!" << endl;
        return false;
    }
    if((int)newTable.columnName.size() == 0){
        cout << "[Error] Can't create a empty table!" << endl;
        return false;
    }
    //--------------------------------------------------------------------
    cout << "[OK] Creating tables  success." << endl;
    kLine::MakeLine(60);
    cout << "Table's name is" << " [" << newTable.name << "]" << endl;
    cout << setiosflags(ios::left);
    cout << setw(15)  << "ColumnName";
    cout << setw(10)  << "type";
    cout << setw(10)  << "unit";
    cout << setw(15)  << "key" << endl;
    for(int i = 0; i < Size; i++){
        //列名字
        cout << setw(15)  << newTable.columnName[i];
        //列种类
        if(newTable.columnType[i] == 1)
            cout << setw(10) << "int";
        if(newTable.columnType[i] == 2)
            cout << setw(10) << "char";
        //
        cout << setw(10) << newTable.columnUnit[i];
        if(newTable.isKey[i] & (1 << 0))
            cout << setw(15) << "[PRIMARY KEY] ";
        if(newTable.isKey[i] & (1 << 1))
            cout << setw(8) << "[UNIQUE] ";
        if(newTable.isKey[i] & (1 << 2))
            cout << setw(10) << "[NOT NULL]";
        cout << endl;
    }
    kLine::MakeLine(60);
    myTable.push_back(newTable);
    return true;
};
Пример #28
0
/*
    对一个表插入数据
*/
bool userDatabase::InsertTable(){
    int Size = mySql.sqlWord.size();
    //int all  = 0;
    vector<string>insertname;                       //需要插入的列名
    vector<string>value;                            //需要插入的值
    vector<string>insertvalue;
    int tableid;
    if(Size >= 4 && mySql.sqlWord[1] == "into"){
        string name = mySql.sqlWord[2];
        tableid = FindTable(name);
        //查找表是否存在
        if(tableid == -1){
            kLine::NotFindTable(name);
            return false;
        }
        //全输入模式
        int tSize = myTable[tableid].columnName.size();
        if(canRead(3) && mySql.sqlWord[3] == "values"){
            for(int i = 4; i < Size; i ++){
                if(canRead(i) && mySql.sqlWord[i] != ",")
                    insertvalue.push_back(mySql.sqlWord[i]);
            }
            //插入的数目和表的数量不一致
            if((int)insertvalue.size() != tSize){
                cout << "[Error] The number of values are error!" << endl;
                return false;
            }
        }
        else{
            for(int i = 0; i < tSize; i++)  insertvalue.push_back("NULL");
            int pos = 3,iSize;
            for(;pos < Size;pos++){
                if(canRead(pos) && mySql.sqlWord[pos] == "values"){
                    pos ++;
                    break;
                }
                if(canRead(pos) && mySql.sqlWord[pos] != ",")
                    insertname.push_back(mySql.sqlWord[pos]);
            }
            for(;pos < Size;pos++){
                if(canRead(pos) && mySql.sqlWord[pos] != ",")
                    value.push_back(mySql.sqlWord[pos]);
            }
            if(insertname.size() != value.size()){
                cout << "[Error] The number of values are error!" << endl;
                return false;
            }
            iSize = insertname.size();
            for(int i = 0; i < iSize; i++){
                int id = myTable[tableid].findColumn(insertname[i]);
                if(id == -1){
                    kLine::NotFindColumn(insertname[i]);
                    return false;
                }
                insertvalue[id] = value[i];
            }
        }
    }
    else{
        return false;
    }
    //for(int i = 0; i < insertname.size(); i++)
    //    cout << insertvalue[i] << endl;
    if(myTable[tableid].insertData(insertvalue)){
        cout << "[OK] Insert Success." << endl;
        kLine::MakeLine(60);
        cout << "Value:" << endl;
        cout << "(";
        for(int i = 0; i < (int)insertvalue.size(); i++)
            cout << "'" << insertvalue[i] << "' ";
        cout << ")" << endl;
        kLine::MakeLine(60);
        return true;
    }
    else
        return false;
}
Пример #29
0
bool CServerDef::r_LoadVal( CScript & s )
{
	ADDTOCALLSTACK("CServerDef::r_LoadVal");
	EXC_TRY("LoadVal");
	switch ( FindTableSorted( s.GetKey(), sm_szLoadKeys, CountOf( sm_szLoadKeys )-1 ) )
	{
		case SC_ACCAPP:
		case SC_ACCAPPS:
			// Treat it as a value or a string.
			if ( IsDigit( s.GetArgStr()[0] ))
				m_eAccApp = static_cast<ACCAPP_TYPE>(s.GetArgVal() );
			else
			{
				// Treat it as a string. "Manual","Automatic","Guest"
				m_eAccApp = static_cast<ACCAPP_TYPE>(FindTable(s.GetArgStr(), sm_AccAppTable, CountOf(sm_AccAppTable)));
			}
			if ( m_eAccApp < 0 || m_eAccApp >= ACCAPP_QTY )
				m_eAccApp = ACCAPP_Unspecified;
			break;
		case SC_AGE:
			break;
		case SC_CLIENTVERSION:
			m_sClientVersion = s.GetArgRaw();
			// m_ClientVersion.SetClientVer( s.GetArgRaw());
			break;
		case SC_CREATE:
			m_timeCreate = CServerTime::GetCurrentTime() - ( s.GetArgLLVal() * TICK_PER_SEC );
			break;
		case SC_ADMINEMAIL:
			if ( this != &g_Serv && !g_Serv.m_sEMail.IsEmpty() && strstr(s.GetArgStr(), g_Serv.m_sEMail) )
				return false;
			if ( !g_Cfg.IsValidEmailAddressFormat(s.GetArgStr()) )
				return false;
			if ( g_Cfg.IsObscene(s.GetArgStr()) )
				return false;
			m_sEMail = s.GetArgStr();
			break;
		case SC_LANG:
			{
				tchar szLang[ 32 ];
				Str_GetBare( szLang, s.GetArgStr(), sizeof(szLang), "<>/\"\\" );
				if ( g_Cfg.IsObscene(szLang) )	// Is the name unacceptable?
					return false;
				m_sLang = szLang;
			}
			break;
		case SC_LASTVALIDDATE:
			m_dateLastValid.Read( s.GetArgStr() );
			break;
		case SC_LASTVALIDTIME:
			{
				int iVal = s.GetArgVal() * TICK_PER_SEC;
				if ( iVal < 0 )
					m_timeLastValid = CServerTime::GetCurrentTime() + iVal;
				else
					m_timeLastValid = CServerTime::GetCurrentTime() - iVal;
			}
			break;
		case SC_SERVIP:
			m_ip.SetHostPortStr( s.GetArgStr() );
			break;

		case SC_NAME:
		case SC_SERVNAME:
			SetName( s.GetArgStr() );
			break;
		case SC_SERVPORT:
			m_ip.SetPort( (word)s.GetArgVal() );
			break;

		case SC_ACCOUNTS:
			SetStat( SERV_STAT_ACCOUNTS, s.GetArgVal() );
			break;

		case SC_CLIENTS:
			{
				int iClients = s.GetArgVal();
				if ( iClients < 0 )
					return false;				// invalid
				if ( iClients > FD_SETSIZE )	// Number is bugged !
					return false;
				SetStat( SERV_STAT_CLIENTS, iClients );
			}
			break;
		case SC_ITEMS:
			SetStat( SERV_STAT_ITEMS, s.GetArgVal() );
			break;
		case SC_CHARS:
			SetStat( SERV_STAT_CHARS, s.GetArgVal() );
			break;
		case SC_TIMEZONE:
			m_TimeZone = (char)s.GetArgVal();
			break;
		case SC_URL:
		case SC_URLLINK:
			// It is a basically valid URL ?
			if ( this != &g_Serv )
			{
				if ( !g_Serv.m_sURL.IsEmpty() && strstr(s.GetArgStr(), g_Serv.m_sURL) )
					return false;
			}
			if ( !strchr(s.GetArgStr(), '.' ) )
				return false;
			if ( g_Cfg.IsObscene( s.GetArgStr()) )	// Is the name unacceptable?
				return false;
			m_sURL = s.GetArgStr();
			break;
		default:
			return CScriptObj::r_LoadVal(s);
	}
	return true;
	EXC_CATCH;

	EXC_DEBUG_START;
	EXC_ADD_SCRIPT;
	EXC_DEBUG_END;
	return false;
}
Пример #30
0
//用户数据的初始化
bool userDatabase::userStart(){
    //read
    int L = username.size();
    char name[256];
    strcpy(name,"user\\");
    int  j = strlen(name);
    for(int i = 0; i < L; i++)
        name[j++] = username[i];
    name[j] = '\0';
    fstream fr(name,ios::in);
    //------------用户数据的读取---------------
    if(fr){
        char data[2048];
        int op = 0;
        while(!fr.eof()){
            fr.getline(data,2048);
            if(data[0] == '#'){
                op ++;
            }
            else{
                if(op == 1 && data[0] != '\0'){
                    string temp_name(data);
                    //cout << "can_read " << temp_name << endl;
                    int id = FindTable(temp_name);
                    //没有被用户读取到
                    if(id == -1){
                        kTable newTable;
                        newTable.name = temp_name;
                        newTable.can_read = true;
                        myTable.push_back(newTable);
                    }
                    else
                        myTable[id].can_read = true;
                }
                if(op == 2 && data[0] != '\0'){
                    string temp_name(data);
                    //cout << "can_write " << temp_name << endl;
                    int id = FindTable(temp_name);
                    if(id == -1){
                        kTable newTable;
                        newTable.name = temp_name;
                        newTable.can_write = true;
                        myTable.push_back(newTable);
                    }
                    else
                        myTable[id].can_write = true;
                }
                if(op == 3 && data[0] != '\0'){
                    string temp_name(data);
                    //
                    kView newView;
                    newView.viewname = temp_name;
                    //cout << newView.viewname << endl;
                    myView.push_back(newView);
                }
                if(op == 4 && data[0] != '\0'){
                    string temp_name(data);
                    kIndex newindex;
                    newindex.name = temp_name;
                    //cout << newindex.name << endl;
                    myIndex.push_back(newindex);
                }
            }
        }
        fr.close();
        //----------用户表数据的读取--------------
        userGetTable();
        userGetView();
        userGetIndex();
        //----------------------------------------
    }
    else{
        ofstream fr(name);
        fr << "#" << endl;
        fr << "#" << endl;
        fr.close();
    }
    //-------------------------------
    return true;
}