Subversion Repositories Programming Utils

Compare Revisions

Ignore whitespace Rev 89 → Rev 90

/trunk/TrainDatabase/dbaccess.cpp
1,6 → 1,7
#include <stdlib.h>
#include <stdio.h>
#include <QString>
#include <QDebug>
 
#include "dbaccess.h"
#include "dbexception.h"
24,13 → 25,7
}
 
if( create ){
error = sqlite3_exec( m_sql, "CREATE TABLE \"Trains\" (\n\
train_id INTEGER PRIMARY KEY NOT NULL,\n\
Reporting_Mark TEXT,\n\
Road_Num INTEGER,\n\
Type TEXT,\n\
Cost INTEGER,\n\
Notes TEXT )",
error = sqlite3_exec( m_sql, "CREATE TABLE \"Trains\" (train_id INTEGER PRIMARY KEY NOT NULL,\n Reporting_Mark TEXT,\n Road_Num INTEGER,\n Type TEXT,\n Cost INTEGER,\n Notes TEXT )",
NULL, NULL, NULL );
if( error ){
QString exc = QString( "Can't create database: %1" ).arg( sqlite3_errmsg( m_sql ) );
121,6 → 116,8
void DBAccess::updateRecord( TrainRecord * rec ){
sqlite3_stmt* res;
int result;
char str[ 1024 ];
size_t copy_len;
if( rec == NULL ){
return;
}
130,7 → 127,13
QString exc = QString( "Can't create prepared statement: %1" ).arg( sqlite3_errmsg( m_sql ) );
throw DBException( exc.toStdString() );
}
sqlite3_bind_text( res, 1, rec->getReportingMark().c_str(), -1, NULL );
 
//note: for some reason on Windows, we can't just pass in the c_str that we get from std::string
//copy the c_str to a char array
copy_len = rec->getReportingMark().length() + 1;
if( copy_len > 1024 ) copy_len = 1024;
memcpy( str, rec->getReportingMark().c_str(), copy_len );
sqlite3_bind_text( res, 1, str, -1, NULL );
sqlite3_bind_int( res, 2, rec->getKey() );
 
result = sqlite3_step( res );
158,7 → 161,10
QString exc = QString( "Can't create prepared statement: %1" ).arg( sqlite3_errmsg( m_sql ) );
throw DBException( exc.toStdString() );
}
sqlite3_bind_text( res, 1, rec->getStockType().c_str(), -1, NULL );
copy_len = rec->getStockType().length() + 1;
if( copy_len > 1024 ) copy_len = 1024;
memcpy( str, rec->getStockType().c_str(), copy_len );
sqlite3_bind_text( res, 1, str, -1, NULL );
sqlite3_bind_int( res, 2, rec->getKey() );
 
result = sqlite3_step( res );
186,7 → 192,10
QString exc = QString( "Can't create prepared statement: %1" ).arg( sqlite3_errmsg( m_sql ) );
throw DBException( exc.toStdString() );
}
sqlite3_bind_text( res, 1, rec->getNotes().c_str(), -1, NULL );
copy_len = rec->getNotes().length() + 1;
if( copy_len > 1024 ) copy_len = 1024;
memcpy( str, rec->getNotes().c_str(), copy_len );
sqlite3_bind_text( res, 1, str, -1, NULL );
sqlite3_bind_int( res, 2, rec->getKey() );
 
result = sqlite3_step( res );