cgicc开发 (结合sqlite3操作数据库)

#include <iostream>
#include <fstream> //读写文件 c++标准库
#include <string> //字符串类 c++标准库
#include <sstream> //字符串流 c++标准库
#include <assert.h>
#include "sqlite3.h"	//sqlite3头文件

#include <cgicc/CgiDefs.h>	//cgicc库头文件
#include <cgicc/Cgicc.h> 
#include <cgicc/HTTPHTMLHeader.h> 
#include <cgicc/HTMLClasses.h> 

using namespace cgicc;
using namespace std;
#define DEBUG false
/********************* 测试模块 ********************/
void testMode()
{
	Cgicc formData;
	//获取文本框内容
	const vector<cgicc::FormEntry>& form_entries = formData.getElements();
	cout << "form_entries.size()=" << form_entries.size() << endl;
	for (vector<cgicc::FormEntry>::size_type i=0; i<form_entries.size(); ++i)
	{
		const cgicc::FormEntry& form_entry = form_entries[i];
		cout << "getName=" << form_entry.getName() << "; getValue=" << form_entry.getValue() << endl;
	}
}

/*****************WG67-Key-In*****************/
static int callback(void *data, int argc, char **argv, char **azColName)
{
#if (DEBUG == true)
	cout << "callback: argc = " << argc 
		 << "; azColName[0] = " << azColName[0] 
		 << "; argv[0] = " << argv[0]
		 << endl;
#endif
	int j = 0;
	for(j = 0; j < argc; j++){
		cout << argv[j];
		if(j < argc - 1){
			cout << ",";
		}
		if(j == argc - 1)
			cout << ";";
	}
	cout << endl;
	return 0;
}

bool SelectMsgFromDB()
{
	bool rtn = true;
	sqlite3 *dataDB;
	string callback_data = "Callback function called";
	char *zErrMsg = 0;
	string dataBaseFilePath = "/opt/diantai.db";
	int select_warn_res = 0;
	string sql_warn_select;
	/* 
	 * Open
	 * Check File Exist
	 * If not Exist it will creat new database
	 */
	int openDBStatus = sqlite3_open(dataBaseFilePath.c_str(), &dataDB);
	if(openDBStatus)
	{
#if (DEBUG == true)
		cout << "Can't open database: " << sqlite3_errmsg(dataDB) << endl;
#endif
		goto exit_error;
		rtn = false;
	}
	
	/* Create SQL statement */
	sql_warn_select = "Select ppt_id,client_sip_host,client_req_type FROM radio_session;";
	/* Execute SQL statement */
	cout << "fid: 000.000" << ";" << endl;
	select_warn_res = sqlite3_exec(dataDB, sql_warn_select.c_str(), callback, (void*)callback_data.c_str(), &zErrMsg);
	if(select_warn_res != SQLITE_OK)
	{
#if (DEBUG == true)
		cout << "SQL(select warn msg) error: " << zErrMsg << endl;
#endif
		sqlite3_free(zErrMsg);
		rtn = false;
	}
exit_error:
	sqlite3_close(dataDB);
	return rtn;
}
/********************* main函数 *********************/
int main(int argc, char *argv[])
{
	cout << "Content-type:text/html;charset=utf-8\r\n\r\n";
#if (DEBUG == true)
	if(argc > 1){
		for(int i = 0; i < argc; i++)
			cout << "main: argv[" << i << "]=" << argv[i] << endl;
	}
	testMode();
#endif
	SelectMsgFromDB();
	return 0;
}

web通过 submit 提交form形式执行cgi程序。

sqlite3操作,参考:SQLite – C/C++ | 菜鸟教程 

cgicc的安装和使用,参考:Cgicc搭建交叉编译环境(移植到arm)-CSDN博客

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值