@@ -1241,20 +1241,20 @@ bool DBBrowserDB::getRow(const sqlb::ObjectIdentifier& table, const QString& row
12411241 return ret;
12421242}
12431243
1244- QString DBBrowserDB::max (const sqlb::ObjectIdentifier& tableName, const sqlb::Field & field) const
1244+ unsigned long DBBrowserDB::max (const sqlb::ObjectIdentifier& tableName, const std::string & field) const
12451245{
1246- QString sQuery = QString (" SELECT MAX(CAST(%2 AS INTEGER)) FROM %1;" ).arg (QString::fromStdString (tableName.toString ())).arg (QString::fromStdString (sqlb::escapeIdentifier (field. name () )));
1246+ QString sQuery = QString (" SELECT MAX(CAST(%2 AS INTEGER)) FROM %1;" ).arg (QString::fromStdString (tableName.toString ())).arg (QString::fromStdString (sqlb::escapeIdentifier (field)));
12471247 QByteArray utf8Query = sQuery .toUtf8 ();
12481248 sqlite3_stmt *stmt;
1249- QString ret = " 0 " ;
1249+ unsigned long ret = 0 ;
12501250
12511251 if (sqlite3_prepare_v2 (_db, utf8Query, utf8Query.size (), &stmt, nullptr ) == SQLITE_OK)
12521252 {
12531253 // even this is a while loop, the statement should always only return 1 row
12541254 while (sqlite3_step (stmt) == SQLITE_ROW)
12551255 {
12561256 if (sqlite3_column_count (stmt) == 1 )
1257- ret = QString::fromUtf8 ( reinterpret_cast < const char *>( sqlite3_column_text (stmt, 0 ) ));
1257+ ret = static_cast < unsigned long >( sqlite3_column_int64 (stmt, 0 ));
12581258 }
12591259 }
12601260 sqlite3_finalize (stmt);
@@ -1281,8 +1281,8 @@ QString DBBrowserDB::emptyInsertStmt(const std::string& schemaName, const sqlb::
12811281 } else {
12821282 if (f.notnull ())
12831283 {
1284- QString maxval = this ->max (sqlb::ObjectIdentifier (schemaName, t.name ()), f);
1285- QString newval = QString::number (maxval. toLongLong () + 1 );
1284+ unsigned long maxval = this ->max (sqlb::ObjectIdentifier (schemaName, t.name ()), f. name () );
1285+ QString newval = QString::number (maxval + 1 );
12861286 vals << (f.isText ()? " '" + newval + " '" : newval);
12871287 } else {
12881288 vals << " NULL" ;
@@ -1338,7 +1338,7 @@ QString DBBrowserDB::addRecord(const sqlb::ObjectIdentifier& tablename)
13381338 {
13391339 // For multiple rowid columns we just use the value of the last one and increase that one by one. If this doesn't yield a valid combination
13401340 // the insert record dialog should pop up automatically.
1341- pk_value = QString::number (max (tablename, * sqlb::findField ( table, table ->rowidColumns ().back ())). toLongLong ( ) + 1 );
1341+ pk_value = QString::number (max (tablename, table->rowidColumns ().back ()) + 1 );
13421342 sInsertstmt = emptyInsertStmt (tablename.schema (), *table, pk_value);
13431343 } else {
13441344 sInsertstmt = emptyInsertStmt (tablename.schema (), *table);
@@ -1900,27 +1900,10 @@ objectMap DBBrowserDB::getBrowsableObjects(const std::string& schema) const
19001900 return res;
19011901}
19021902
1903- void DBBrowserDB::logSQL (QString statement, LogMessageType msgtype)
1903+ void DBBrowserDB::logSQL (const QString& statement, LogMessageType msgtype)
19041904{
19051905 // Remove any leading and trailing spaces, tabs, or line breaks first
1906- statement = statement.trimmed ();
1907-
1908- // Replace binary log messages by a placeholder text instead of printing gibberish
1909- for (int i=0 ;i<statement.size ();i++)
1910- {
1911- QChar ch = statement[i];
1912- if (ch < 32 && ch != ' \n ' && ch != ' \r ' && ch != ' \t ' )
1913- {
1914- statement.truncate (i>0 ?i-1 :0 );
1915- statement.append (tr (" ... <string can not be logged, contains binary data> ..." ));
1916-
1917- // early exit if we detect a binary character,
1918- // to prevent checking all characters in a potential big string
1919- break ;
1920- }
1921- }
1922-
1923- emit sqlExecuted (statement, msgtype);
1906+ emit sqlExecuted (statement.trimmed (), msgtype);
19241907}
19251908
19261909void DBBrowserDB::updateSchema ()
@@ -1967,21 +1950,23 @@ void DBBrowserDB::updateSchema()
19671950 {
19681951 std::string val_type = reinterpret_cast <const char *>(sqlite3_column_text (vm, 0 ));
19691952 std::string val_name = reinterpret_cast <const char *>(sqlite3_column_text (vm, 1 ));
1970- QString val_sql = QString::fromUtf8 ( reinterpret_cast <const char *>(sqlite3_column_text (vm, 2 ) ));
1953+ const char * val_sql = reinterpret_cast <const char *>(sqlite3_column_text (vm, 2 ));
19711954 std::string val_tblname = reinterpret_cast <const char *>(sqlite3_column_text (vm, 3 ));
1972- val_sql = val_sql.replace (" \r " , " " );
19731955
1974- if (! val_sql. isEmpty () )
1956+ if (val_sql)
19751957 {
1958+ std::string sql = val_sql;
1959+ sql.erase (std::remove (sql.begin (), sql.end (), ' \r ' ), sql.end ());
1960+
19761961 sqlb::ObjectPtr object;
19771962 if (val_type == " table" )
1978- object = sqlb::Table::parseSQL (val_sql. toStdString () );
1963+ object = sqlb::Table::parseSQL (sql );
19791964 else if (val_type == " index" )
1980- object = sqlb::Index::parseSQL (val_sql. toStdString () );
1965+ object = sqlb::Index::parseSQL (sql );
19811966 else if (val_type == " trigger" )
1982- object = sqlb::Trigger::parseSQL (val_sql. toStdString () );
1967+ object = sqlb::Trigger::parseSQL (sql );
19831968 else if (val_type == " view" )
1984- object = sqlb::View::parseSQL (val_sql. toStdString () );
1969+ object = sqlb::View::parseSQL (sql );
19851970 else
19861971 continue ;
19871972
0 commit comments