Gcc sqlite3_准备错误c++;x64 TDM下的cygwin

Gcc sqlite3_准备错误c++;x64 TDM下的cygwin,gcc,sqlite,Gcc,Sqlite,我正在编译一个示例应用程序,它使用源代码sqlite3 我的windows x64计算机上的代码 #include "sqlite3.h" #include <stdio.h> #include <string.h> #include <windows.h> int main(int argc,char **argv) { sqlite3 *db; sqlite3_stmt * pSqllite3_stmt=NULL; char *zErrMsg

我正在编译一个示例应用程序,它使用源代码sqlite3 我的windows x64计算机上的代码

#include "sqlite3.h"
#include <stdio.h>
#include <string.h>
#include <windows.h>

int main(int argc,char **argv)
{
  sqlite3 *db;
  sqlite3_stmt * pSqllite3_stmt=NULL;
  char *zErrMsg=0;
  int rc;

  // create a new database //
  rc =sqlite3_open( ".\\sql_lite3.db" ,&db);
  if(rc!=SQLITE_OK|| db == NULL)
  {
      MessageBox(NULL,TEXT("can't open the database") , TEXT("sql_lite example"), MB_OK);
      exit(0);
  }

  // create a table called string_index //
  char * create_query = "create table string_table (index INT ,string TEXT);" ;
  rc = sqlite3_prepare_v2( db , create_query, -1, &pSqllite3_stmt,NULL);
  if (rc != SQLITE_OK ) { 
    // if an error occurred //
    char error_code[128];
    sprintf(error_code," Error Code is %d" ,rc);

    MessageBox( NULL, error_code,TEXT("sql_lite example"), MB_OK);
    exit(0);
  }

  // step the create query //
  rc = sqlite3_step(pSqllite3_stmt);
  if(SQLITE_OK != rc)
  {
    MessageBox(NULL,TEXT("Create step have failed "),TEXT("sql lite example"),MB_OK);
    exit(0);  
  }


  // insert records to the database //
  char *insert_query = new char [ 1024];
  int i;
  sqlite3_stmt * insert_stmt ;
  char * insert_string ="This is the insert String";
  for (i=1; i<= 10;i++){
    sprintf( insert_query,"INSERT INTO string_table(index,string) VALUES(%d,?1);" , \
                   i);
    // execute the insert query //
    rc = sqlite3_prepare_v2(db , insert_query,strlen(insert_query), &insert_stmt,NULL);
    if(rc!= SQLITE_OK)
    {
      MessageBox(NULL,TEXT("INSERT INTO have been failed"), TEXT("SQLITE EXAMPLE"),MB_OK);
      exit(0);
    }

    // bind the string //
    rc =sqlite3_bind_text(insert_stmt,1,insert_string,sizeof(insert_string),SQLITE_TRANSIENT);
    if(rc != SQLITE_OK && rc != SQLITE_DONE)
    {
      MessageBox(NULL,TEXT("bind failed"),TEXT("SQLITE EXAMPLE"), MB_OK);
      exit(0);
    }
    // call step //
    rc = sqlite3_step(insert_stmt);
    if( rc != SQLITE_OK)
    {
      MessageBox(NULL,TEXT("Insertion step failed "),TEXT("SQLITE EXAMPLE"),MB_OK);
      exit(0);
    }

    // finalize the insert query //
    sqlite3_finalize(insert_stmt);
  } 

  // now we are going to execute the search query //
  char * search_query = "SELECT * FROM string_table WHERE index=10";
  sqlite3_stmt * search_stmt ;
  rc = sqlite3_prepare_v2(db,search_query,sizeof(search_query),&search_stmt,NULL); 
  if( SQLITE_OK== rc)
  {
    while( SQLITE_ROW == sqlite3_step(search_stmt ) )
    {
      // print the record //
      const int  index_value= sqlite3_column_int(search_stmt,1);
      const unsigned char * string_value = sqlite3_column_text(search_stmt,2);
      printf( "index :%d and string:%s ",index_value,string_value );

    }
  }else{
    MessageBox(NULL,TEXT("Searching query sqlite3 have been failed"),TEXT("SQLITE example"), MB_OK);
    exit(0);
  }

  // fnalize the search statement //
  sqlite3_finalize(search_stmt);

  // don't forget to close the connection //
  sqlite3_close(db);

  return 0;
 }
为什么呢?我怎样才能克服这个问题

有什么建议或改进吗


--提前感谢--

要显示有用的错误消息,请使用:

MessageBox(0,sqlite3\u errmsg(db),NULL,0);

至于您的SQL命令:
index
是一个,因此您必须在使用它时引用它:

创建表字符串\u表(“索引”INT,字符串文本);

使用其他列名可能更容易。

要显示有用的错误消息,请使用:

MessageBox(0,sqlite3\u errmsg(db),NULL,0);

至于您的SQL命令:
index
是一个,因此您必须在使用它时引用它:

创建表字符串\u表(“索引”INT,字符串文本);

使用其他列名可能更容易。

编辑器中设置了哪些源文件编码?sqlite3\u prepare\u v2需要UTF8字符串编辑器中设置了哪些源文件编码?sqlite3_prepare_v2需要UTF8字符串接受答案,当我这样写时
“如果不存在,创建表stringtable(\“index\”INT,string TEXT);”它工作!我接受了答案,当我这样写的时候,
“如果不存在,创建表stringtable(\'index\'INT,stringtext);”它工作!
 // create a table called string_index //
  char * create_query = "create table string_table (index INT ,string TEXT);" ;
  rc = sqlite3_prepare_v2( db , create_query, -1, &pSqllite3_stmt,NULL);
  if (rc != SQLITE_OK ) { 
    // if an error occurred //
    char error_code[128];
    sprintf(error_code," Error Code is %d" ,rc);

    MessageBox( NULL, error_code,TEXT("sql_lite example"), MB_OK);
    exit(0);
  }