Exemple #1
0
bool Dictionary::AddTable(TableInfo* tableInfo)
{
    if (tableInfo == NULL || tableInfo->Fields == NULL)
        return false;
    if (TableExist(tableInfo->TName))
    {
        return false;
    }
    uint tid = ++MaxTID;
    TableNum++;
    TabDicLen++;
    TableDict = (TableDictItem *)realloc(TableDict, sizeof(TableDictItem)*TabDicLen);
    TableDict[TabDicLen-1].TID = tid;
    strcpy(TableDict[TabDicLen-1].DataPath, tableInfo->DataPath);
    strcpy(TableDict[TabDicLen-1].MetaPath, tableInfo->MetaPath);
    strcpy(TableDict[TabDicLen-1].TName, tableInfo->TName);
    TableDict[TabDicLen-1].FieldNum = tableInfo->FieldNum;
    TableDict[TabDicLen-1].TupleNum = tableInfo->TupleNum;
    TableDict[TabDicLen-1].BlockNum = tableInfo->BlockNum;
    TableDict[TabDicLen-1].Valid = true;
    uint i = FieDicLen, j;
    FieldNum += tableInfo->FieldNum;
    FieDicLen += tableInfo->FieldNum;
    FieldDict = (FieldDictItem *)realloc(FieldDict, sizeof(FieldDictItem)*FieDicLen);
    for (j = 0; i < FieDicLen; ++i, ++j)
    {
        strcpy(FieldDict[i].FName, tableInfo->Fields[j].FName);
        FieldDict[i].IsPrimaryKey = tableInfo->Fields[j].IsPrimaryKey;
        FieldDict[i].IsUnique = tableInfo->Fields[j].IsUnique;
        FieldDict[i].BuildHashIndex = tableInfo->Fields[j].BuildHashIndex;
        FieldDict[i].BuildBPTIndex = tableInfo->Fields[j].BuildBPTIndex;
        FieldDict[i].Size = tableInfo->Fields[j].Size;
        FieldDict[i].Type = tableInfo->Fields[j].Type;
        FieldDict[i].TID = tid;
        FieldDict[i].Valid = true;
    }
    M = true;
    return true;
}
Exemple #2
0
BOOL CheckDataBaseExist()//返回1,则表示数据库已存在;返回0,则表示不存在并创建
{
	convert_char(_T("\\ResidentFlash\\Config\\RFIDData.db"));

	int res = sqlite3_open(send_data, &pDB);
	if(res)
	{
		AfxMessageBox(_T("打开数据库错误"));
		return FALSE;
	}

	char* errMsg;
	CString strTemp;
	char temp_data[1024]={'\0'};
	//Create bus_depart table
	if(!TableExist(_T("bus_depart"))){
		strTemp = "create table bus_depart (bus_run_ID CHAR(30) NOT NULL PRIMARY KEY, bus_ID CHAR(10), driver_ID CHAR(10), teacher_ID CHAR(10), road_ID CHAR(10), student_number INTEGER, remark VARCHAR(255))";
		memset(temp_data, 0x00, sizeof(temp_data));
		WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strTemp,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL);
		res = sqlite3_exec(pDB,temp_data,0,0, &errMsg);
		if (res != SQLITE_OK)
		{
	#ifdef DEBUG_YFH
			AfxMessageBox(_T("创建表1错误"));
	#endif
		}
	}else{
		//AfxMessageBox(_T("表1已经存在!"));
	}

	//Create bus_stu table
	if(!TableExist(_T("bus_stu"))){
		strTemp = "create table bus_stu (bus_run_ID CHAR(20) NOT NULL, student_ID CHAR(10) NOT NULL, up_station_ID CHAR(10), up_time TIME, down_station_ID CHAR(10), down_time TIME, remark VARCHAR(255),  PRIMARY KEY(bus_run_ID, student_ID))";
		memset(temp_data, 0x00, sizeof(temp_data));
		WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strTemp,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL);
		res = sqlite3_exec(pDB,temp_data,0,0, &errMsg);
		if (res != SQLITE_OK)
		{
	#ifdef DEBUG_YFH
			AfxMessageBox(_T("创建表2错误"));
	#endif
		}
	}else{
		//AfxMessageBox(_T("表2已经存在!"));
	}

	//create schoolbus table
	if(!TableExist(_T("schoolbus"))){
		strTemp = "create table schoolbus (ID INTEGER PRIMARY KEY AUTOINCREMENT, StudentName VARCHAR(16),ParentPhoneNum VARCHAR(16),UpBusTime VARCHAR(10),IsUpMessageSended VARCHAR(10),DownBusTime VARCHAR(10),IsDownMessageSended VARCHAR(10),BusCode VARCHAR(10))";
		memset(temp_data, 0x00, sizeof(temp_data));
		WideCharToMultiByte(CP_ACP,0,(LPCWSTR)strTemp,-1,(LPSTR)temp_data,sizeof(temp_data),NULL,NULL);
		res = sqlite3_exec(pDB,temp_data,0,0, &errMsg);
		if (res != SQLITE_OK)
		{
			AfxMessageBox(_T("创建表3错误"));
		}
	}else{
		//AfxMessageBox(_T("表3已经存在!"));
	}

	//AfxMessageBox(_T("现在开始测试数据库!"));
	TestDatabase();

	return TRUE;
}