Click here to Skip to main content
11,648,785 members (82,614 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Sqlite
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);

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.
Posted 21-Jun-12 10:32am
amarasat1.4K
Comments
Wes Aday at 21-Jun-12 16:34pm
   
pSQL[0] = "insert into Movies (Title, Director, Year) values ('" + textvalue + "', 'Nolan', 2008)";

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);

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.


EDIT: 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);
}
  Permalink  
v2
Comments
Sandeep Mewara at 22-Jun-12 1:53am
   
My 5!
amarasat at 22-Jun-12 10:29am
   
Thanks alot for your help!! Both ways have worked!!

My 5 too!
amarasat at 22-Jun-12 15:59pm
   
How do i solve this:

CString textvalue = _T("120");
CString Tag = _T("Plugin1@PLG.Value1@Value");
queryStr.Format(L"update Table set Value=%s where Tag=%s", textvalue, Tag);
char *pSQL[0] = T2A(queryStr);
int rc = sqlite3_exec(database, pSQL[i], callback, 0, &zErrMsg);

gives me an error: "near "@PLG": syntax error"

also for Tag = _T("Main Plugin1@PLG.Value1@Value");

gives me an error: "near "Plugin1": syntax error"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 F-ES Sitecore 409
1 CPallini 370
2 OriginalGriff 334
3 Kornfeld Eliyahu Peter 324
4 Sergey Alexandrovich Kryukov 254
0 OriginalGriff 1,512
1 Sergey Alexandrovich Kryukov 1,022
2 jyo.net 994
3 DamithSL 986
4 CPallini 945


Advertise | Privacy | Mobile
Web04 | 2.8.150804.4 | Last Updated 22 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100