Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用libcurl函数传输Sqlite DB文件,但无法立即打开DB文件将数据发送到数据库 我正在运行一个C++程序,它与一个基于PLC的机器通信。_C++_Sqlite_Ftp_Libcurl - Fatal编程技术网

使用libcurl函数传输Sqlite DB文件,但无法立即打开DB文件将数据发送到数据库 我正在运行一个C++程序,它与一个基于PLC的机器通信。

使用libcurl函数传输Sqlite DB文件,但无法立即打开DB文件将数据发送到数据库 我正在运行一个C++程序,它与一个基于PLC的机器通信。,c++,sqlite,ftp,libcurl,C++,Sqlite,Ftp,Libcurl,基于PLC的机器在处理零件后创建.db(SQLITE)文件 我编写了一个函数,使用libcurl函数将sqlite db从PLC机器传输到PC 传输完成后,我需要遍历db文件并将数据传输到公司网络数据库表 我有一个问题,循环通过文件一旦传输完成 读取文件时引发异常“(11)SQLITE_损坏”-“磁盘映像格式不正确” 但一旦我关闭了C++应用程序并再次打开,最后一个SQLite DB文件就可以打开和循环。 我正在附上下面的代码,请告诉我是否有办法使db文件在通过libcurl库传输后可以读取。我

基于PLC的机器在处理零件后创建.db(SQLITE)文件

我编写了一个函数,使用libcurl函数将sqlite db从PLC机器传输到PC

传输完成后,我需要遍历db文件并将数据传输到公司网络数据库表

我有一个问题,循环通过文件一旦传输完成

读取文件时引发异常“(11)SQLITE_损坏”-“磁盘映像格式不正确”

但一旦我关闭了C++应用程序并再次打开,最后一个SQLite DB文件就可以打开和循环。 我正在附上下面的代码,请告诉我是否有办法使db文件在通过libcurl库传输后可以读取。我是否应该使用一些额外的命令使其可用。


问题的解决方案是,在上述代码中,我们忘记关闭“打开的”ftp文件(ofile)


参考链接-[

问题的解决方案是,在上述代码中,我们忘记了关闭“打开的”ftp文件(ofile)

参考链接-[

char dbfile[128];
char ofile[512];

//Pulling all the information about the ftp server information from parsed.xml -> Request/DataBlock/LogFile/Host, Path, File

char *host = tagTextValue(doc, "REQUEST.DATABLOCK.LOGFILE.HOST");// -- 172.16.1.100
if (host) 
{
    if (char *path = tagTextValue(doc, "REQUEST.DATABLOCK.LOGFILE.PATH")) // -- /pub/export/mdt
    {
        if (char *file= tagTextValue(doc, "REQUEST.DATABLOCK.LOGFILE.FILE"))// --  20200226_004636_90180.db
        {
            sprintf_s( dbfile, sizeof(dbfile), "ftp://%s/%s/%s", host, path, file );//Host Address  
            sprintf_s(ofile, sizeof(ofile), "c:\\xxxxx\\xxxxx\\%s", file);//Destination Address
        }
    }
}

///////////Start of FTP///////////////////
struct FtpFile 
{
  const char *filename;
  FILE *stream;
};

FtpFile ftp = 
{
    ofile, /* name to store the file as if successful */ 
    NULL
};



CURL *url = curl_easy_init();
curl_easy_setopt(url,  CURLOPT_URL, dbfile);// dbfile has the complete path where to pull the file from.

FILE *ffp = fopen(ofile, "w"); // ofile mentions the destination on the receiving end

curl_easy_setopt(url, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(url, CURLOPT_WRITEDATA, &ftp);
curl_easy_setopt(url, CURLOPT_USERPWD, "ftpuser:xxxx");// Passing the login details to FTP server to pull the information from the 'server/machine'

CURLcode  res = curl_easy_perform(url);

fclose(ffp);
curl_easy_cleanup(url);

////////////////End of FTP/////////////////////////

sqlite3 *db;

sqlite3_stmt *stmt;

char sql[1024];

Sleep(20000);

WireBondDataUploadType      rec = rec2;         
const char* sql1 = "select xxxxxxxxxx";
bool storeSuccessful = false;

const char *ofile2 = "c:\\xxxxx\\xxxxxxx\\20200310_021605_20039.db";
int rc;
rc = sqlite3_open(ofile, &db);  //ST Opening a new Database connection

if (rc == SQLITE_OK)
{
    rc=sqlite3_prepare(db, sql1, -1, &stmt, NULL);
    if(rc != 0)
    {
        sqlite3_close(db);
    } 
    else if(rc == SQLITE_OK) 
    {
      //Process the information by reading the db file.
      xxxxxxxx
      xxxxxxxx
    }
}