将CString的值添加到SQLite数据库

问题描述:

我想将我的CString的值添加到已经创建的datbase中.

I want to add the value of my CString into the datbase i already created.

CString textvalue  = _T("DarkKnight");
const char *pSQL[1];
pSQL[0] = "insert into Movies (Title, Director, Year) values (''+textvalue+'', 'Nolan', 2008)";
int rc = sqlite3_exec(database, pSQL[0], callback, 0, &zErrMsg);



当我执行命令时,我收到一条错误消息数据库中没有名称为textvalue的列".

如何在运行时将值"DarkKnight"插入SQLite数据库.



When i am executing the command i am getting an error message "There is no column by name textvalue in the database".

How do i insert the value "DarkKnight" into the SQLite database at runtime.

这里是我在C ++ cgi模块中使用的代码. >
Here''s the code I use in a C++ cgi module.

sprintf(buffer, "INSERT INTO `cds` (title,artist,year) VALUES('%s','%s',%d)", bTitle.c_str(), bArtist.c_str(), yr);
queryStr = buffer;
db.exe(queryStr);



大概,您似乎已经在PHP中使用过mySql,这是因为您希望用变量的内容代替变量名.


我在MFC中重击的内容:



At a guess, it looks like you''ve used mySql before in PHP from the way you expect to have the contents of the variable substituted for the variable name.


something I whacked together in MFC:

void CmfcSqliteDlg::OnBnClickedButton1()
{
	USES_CONVERSION;
	CString queryStr;
	CString artStr, albStr, yrStr;
	
	artStr = _T("DeadMau5");
	albStr = _T("4x4 = 12");
	yrStr = _T("2010");

	queryStr.Format(L"insert into cds (title, artist, year) values('%s', '%s', %s)", artStr, albStr, yrStr);
	char *charStr = T2A(queryStr);

	MessageBox(queryStr, _T("Query to execute"));
	MessageBoxA(NULL, charStr, "Query to exeute", MB_OK);
}