설치 프로그램이 배치 한 파일의 데이터베이스 인 sqlite3 명령 줄 도구를 사용하여 다음과 같이 열고 읽고 업데이트 할 수 있습니다.
C:\ProgramData\spectronix\oximeter>C:\Users\James\code\bin\sqlite3 spectrumalpha.dat
SQLite version 3.16.2 2017-01-06 16:32:41
Enter ".help" for usage hints.
sqlite> .schema
CREATE TABLE run ( run INTEGER PRIMARY KEY, timestamp, desc );
CREATE TABLE distance ( hwid, distance );
CREATE TABLE spectrum ( run, timestamp, hwid, distance, data );
CREATE TABLE waveDescription ( run, timestamp, hwid );
CREATE TABLE wave ( wave, idx, data );
sqlite> select desc from run where run is 5;
update from sqlite3 tool
sqlite> UPDATE run SET desc='update #2 from sqlite3 tool' WHERE run IS 5;
sqlite> select desc from run where run is 5;
update #2 from sqlite3 tool
하지만이 코드를 실행하면
#include <iostream>
#include "sqlite3.h"
int main()
{
sqlite3 * db;
sqlite3_stmt *st = 0;
int ret;
char const * tail = 0;
ret = sqlite3_open("C:/ProgramData/spectronix/oximeter/spectrumalpha.dat",&db);
std::cout << "working with db in "
<< sqlite3_db_filename( db, "main" ) << "\n";
// read initial value
ret = sqlite3_prepare_v2(
db,
"SELECT desc FROM run WHERE run IS 5;"
, -1, &st, &tail );
if( ret != SQLITE_OK )
throw std::runtime_error("sqlite first read");
sqlite3_step( st );
std:: cout << "first read is " << sqlite3_column_text(st, 0) << "\n";
sqlite3_finalize( st );
return 0;
}
출력은 이전 버전의 데이터를 보여줍니다.
working with db in C:\ProgramData\spectronix\oximeter\spectrumalpha.dat
first read is test4
또 다른 이상한 점은 라이브러리 코드가 데이터 업데이트를 거부한다는 것입니다.
#include <iostream>
#include "sqlite3.h"
int main()
{
sqlite3 * db;
sqlite3_stmt *st = 0;
int ret;
char const * tail = 0;
ret = sqlite3_open("C:/ProgramData/spectronix/oximeter/spectrumalpha.dat",&db);
std::cout << "working with db in "
<< sqlite3_db_filename( db, "main" ) << "\n";
// read initial value
ret = sqlite3_prepare_v2(
db,
"SELECT desc FROM run WHERE run IS 5;"
, -1, &st, &tail );
if( ret != SQLITE_OK )
throw std::runtime_error("sqlite first read");
sqlite3_step( st );
std:: cout << "first read is " << sqlite3_column_text(st, 0) << "\n";
sqlite3_finalize( st );
// update value
ret = sqlite3_prepare_v2(
db,
"UPDATE run SET desc = 'new_value' WHERE run IS 5;"
, -1, &st, &tail );
if( ret != SQLITE_OK )
throw std::runtime_error("sqlite update error");
sqlite3_finalize( st );
std::cout << sqlite3_changes( db ) << " rows updated\n";
return 0;
}
출력
working with db in C:\ProgramData\spectronix\oximeter\spectrumalpha.dat
first read is test4
0 rows updated
데이터베이스를 응용 프로그램의 작업 디렉토리로 이동하여 데이터베이스를 여는 호출을
ret = sqlite3_open("spectrumalpha.dat",&db);
그러나 같은 문제가 발생합니다.
그래서 마지막으로 데이터베이스를 삭제하고 처음부터 다시 생성했습니다. 그것이 무엇이든간에 문제는 사라졌습니다! 누구든지 그것이 재발하는 경우에 대해 어떤 아이디어가 있습니까?
다음날 설치 프로그램 을 사용 하여 데이터베이스 파일을 작성한 후 문제가 반환되었습니다 .
설치 프로그램은 일부 사용자에게는 쓰기 권한이 있고 다른 사용자에게는 읽기 전용으로 파일을 생성했습니다. 유닉스의 전형적인 걸림돌이지만 윈도우에서 다루어야하는 것에 익숙하지 않습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다