⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 db_func.cpp

📁 一个简单的公交查询管理系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
}


int DB_STATION_TYPE_Modify(SQLHSTMT g_hstmt, char *old_station_type, char *new_station_type)  
{
	//
	SQLCHAR *SqlStatement;
	//  
	SQLINTEGER cbold_station_type = SQL_NTS;
	SQLINTEGER cbnew_station_type = SQL_NTS;
    //Sql Statement
	SqlStatement =(unsigned char *) "UPDATE station_type SET station_type_name=? WHERE station_type_name=?";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//绑定插入参数
	retcode = SQLBindParameter(g_hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(new_station_type),0,new_station_type,strlen(new_station_type),&cbnew_station_type);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}
	
	retcode = SQLBindParameter(g_hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(old_station_type),0,old_station_type,strlen(old_station_type),&cbold_station_type);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLExecute error!");
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
		
	}
	
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	
	//
	return 0;
	

}  


int DB_STATION_TYPE_Delete(SQLHSTMT g_hstmt, char *station_type)

{
	SQLCHAR *SqlStatement;
	//  
	SQLINTEGER cbstation_type = SQL_NTS;
    //Sql Statement
	SqlStatement =(unsigned char *) "DELETE FROM station_type WHERE station_type_name=?";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//绑定插入参数
	retcode = SQLBindParameter(g_hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_type),0,station_type,strlen(station_type),&cbstation_type);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}
	
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
		
	}
	
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	
	//
	return 0;
}



int DB_STATION_TYPE_Delete_All(SQLHSTMT g_hstmt)
{
    SQLCHAR *SqlStatement;
	//  
    //Sql Statement
	SqlStatement =(unsigned char *) "DELETE FROM station_type";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
		
	}
	
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	
	//
	return 0;
}



int DB_STATION_TYPE_Insert(SQLHSTMT g_hstmt, char *station_type)
{
	SQLCHAR *SqlStatement;
	//    
	SQLINTEGER cbstation_type = SQL_NTS;
    //Sql Statement
	SqlStatement =(unsigned char *) "INSERT INTO station_type (station_type_name) VALUES (?)";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//绑定插入参数
	retcode = SQLBindParameter(g_hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_type),0,station_type,strlen(station_type),&cbstation_type);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}
	
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
		
	}
	
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	
	//
	return 0;

}
//////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////

int DB_STATION_INFOR_Query(SQLHSTMT g_hstmt, STATION_INFOR *station_infor, STATION_INFOR *head)
{
	STATION_INFOR *pS,*pEnd;
	SQLCHAR *SqlStatement;
	//    
	SQLINTEGER cbStation_Name      = SQL_NTS;
	SQLINTEGER cbStation_Type_Name = SQL_NTS;
    //Sql Statement
	
	SqlStatement = (unsigned char *) " SELECT station_name,station_type_name FROM station_infor ORDER BY station_type_name,station_name ASC"; //ORDER BY station_type_name ASC";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//绑定列参数
	retcode = SQLBindCol(g_hstmt,1,SQL_C_CHAR,station_infor->Station_Name,sizeof(station_infor->Station_Name),&cbStation_Name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindCol error!");
		return -1;
	}
	
	
	retcode = SQLBindCol(g_hstmt,2,SQL_C_CHAR,station_infor->Station_Type_Name,sizeof(station_infor->Station_Type_Name),&cbStation_Type_Name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindCol error!");
		return -1;
	}
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLExecute error!");
		return -1;
	}
	
	//获取数据
    retcode = SQLFetch(g_hstmt);
    if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
	}
	
	//赋值
	strcpy(head->Station_Name,      station_infor->Station_Name);
	strcpy(head->Station_Type_Name, station_infor->Station_Type_Name);
	
    pEnd = head;
	memset(station_infor,0,sizeof(STATION_INFOR));
	while ( (retcode=SQLFetch(g_hstmt)) != SQL_NO_DATA )
	{ 
		pS = new STATION_INFOR;
		memset(pS,0,sizeof(STATION_INFOR));
		//赋值
		//赋值
		strcpy(pS->Station_Name,      station_infor->Station_Name);
		strcpy(pS->Station_Type_Name, station_infor->Station_Type_Name);
		
		pEnd->next = pS;
		pEnd = pS;
		memset(station_infor,0,sizeof(STATION_INFOR));
	}    //end of while  
	
	pEnd->next = NULL;
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	//
	return 0;
	
}

int DB_STATION_INFOR_Query_StationName(SQLHSTMT g_hstmt, STATION_INFOR *station_infor, STATION_INFOR *head, char *station_type_name)
{
	STATION_INFOR *pS,*pEnd;
	SQLCHAR *SqlStatement;
	//    
	SQLINTEGER cbStation_Name      = SQL_NTS;
	SQLINTEGER cbstation_type_name = SQL_NTS;
    //Sql Statement
	
	SqlStatement = (unsigned char *) " SELECT station_name FROM station_infor where station_type_name=? ORDER BY station_type_name,station_name ASC"; //ORDER BY station_type_name ASC";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	//绑定参数
	retcode = SQLBindParameter(g_hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_type_name),0,station_type_name,strlen(station_type_name),&cbstation_type_name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}

	//绑定列参数
	retcode = SQLBindCol(g_hstmt,1,SQL_C_CHAR,station_infor->Station_Name,sizeof(station_infor->Station_Name),&cbStation_Name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindCol error!");
		return -1;
	}
	
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLExecute error!");
		return -1;
	}
	
	//获取数据
    retcode = SQLFetch(g_hstmt);
    if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
	}
	
	//赋值
	strcpy(head->Station_Name,      station_infor->Station_Name);
	strcpy(head->Station_Type_Name, station_infor->Station_Type_Name);
	
    pEnd = head;
	memset(station_infor,0,sizeof(STATION_INFOR));
	while ( (retcode=SQLFetch(g_hstmt)) != SQL_NO_DATA )
	{ 
		pS = new STATION_INFOR;
		memset(pS,0,sizeof(STATION_INFOR));
		//赋值
		//赋值
		strcpy(pS->Station_Name,      station_infor->Station_Name);
		strcpy(pS->Station_Type_Name, station_infor->Station_Type_Name);
		
		pEnd->next = pS;
		pEnd = pS;
		memset(station_infor,0,sizeof(STATION_INFOR));
	}    //end of while  
	
	pEnd->next = NULL;
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	//
	return 0;
	
}

int DB_STATION_INFOR_Query_BusNumber(SQLHSTMT g_hstmt, char *station_name, char *bus_number)
{
	SQLCHAR *SqlStatement;
	//    
	SQLINTEGER cbstation_name = SQL_NTS;
	SQLINTEGER cbbus_number   = SQL_NTS;
    //Sql Statement
	
	SqlStatement = (unsigned char *) " SELECT bus_number FROM station_infor WHERE station_name=?"; //ORDER BY station_type_name ASC";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//绑定参数
	retcode = SQLBindParameter(g_hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_name),0,station_name,strlen(station_name),&cbstation_name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}

	//绑定列参数
	retcode = SQLBindCol(g_hstmt,1,SQL_C_CHAR, bus_number,128,&cbbus_number);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindCol error!");
		return -1;
	}
		
    
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLExecute error!");
		return -1;
	}
	
	//获取数据
    retcode = SQLFetch(g_hstmt);
    if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		//关闭
		retcode = SQLFreeStmt(hstmt,SQL_CLOSE);
		if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
		{
			AfxMessageBox("SQLCloseCursor!");
			return -1;
		} 
		return -1;
	}
	
	
    //关闭当前
	retcode = SQLFreeStmt(g_hstmt,SQL_CLOSE);
	if( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) )
	{
		AfxMessageBox("SQLFreeStmt error!");
		return -1;
	} 	
	//
	return 0;

}

int DB_STATION_INFOR_Modify(SQLHSTMT g_hstmt, STATION_INFOR *station_infor, char *station_name)   
{
	//
	SQLCHAR *SqlStatement;
	//  
	SQLINTEGER cbBus_Number    = SQL_NTS;
	SQLINTEGER cbstation_name = SQL_NTS;
	SQLINTEGER cbStation_Name = SQL_NTS;
	SQLINTEGER cbStation_Type_Name = SQL_NTS;
    //Sql Statement
	SqlStatement =(unsigned char *) "UPDATE station_infor SET station_name=?,bus_number=?,station_type_name=? WHERE station_name=?";
	
	//Prepare
	retcode = SQLPrepare(g_hstmt,SqlStatement,SQL_NTS);
	if ((retcode!= SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("prepare error!");
		return -1;
	}
	
	//绑定参数
	retcode = SQLBindParameter(g_hstmt,1,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_infor->Station_Name),0,station_infor->Station_Name,strlen(station_infor->Station_Name),&cbStation_Name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}

	retcode = SQLBindParameter(g_hstmt,2,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_infor->Bus_Number),0,station_infor->Bus_Number,strlen(station_infor->Bus_Number),&cbBus_Number);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}
	
	retcode = SQLBindParameter(g_hstmt,3,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_infor->Station_Type_Name),0,station_infor->Station_Type_Name,strlen(station_infor->Station_Type_Name),&cbStation_Type_Name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}

	retcode = SQLBindParameter(g_hstmt,4,SQL_PARAM_INPUT,SQL_C_CHAR,SQL_CHAR,strlen(station_name),0,station_name,strlen(station_name),&cbstation_name);
	if ((retcode!=SQL_SUCCESS) && (retcode!=SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLBindParameter error!");
		return -1;
	}
	//执行查询
	retcode = SQLExecute(g_hstmt);
	if ((retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO))
	{
		AfxMessageBox("SQLExecute error!");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -