93 } |
93 } |
94 |
94 |
95 // to prevent nameclashes on our database server, each machine |
95 // to prevent nameclashes on our database server, each machine |
96 // will use its own set of table names. Call this function to get |
96 // will use its own set of table names. Call this function to get |
97 // "tablename_hostname" |
97 // "tablename_hostname" |
98 inline static QString qTableName( const QString& prefix, QSqlDriver* driver = 0 ) |
98 inline static QString qTableName( const QString& prefix, const char *sourceFileName ) |
99 { |
99 { |
100 if ( !driver ) |
100 return QLatin1String("dbtst")+QString::number(qHash(QLatin1String(sourceFileName) + "_" + qGetHostName().replace( "-", "_" )), 16)+"_"+prefix; |
101 return prefix + "_" + qGetHostName().replace( "-", "_" ); |
101 } |
102 else |
102 |
103 return driver->escapeIdentifier( prefix + "_" + qGetHostName(), QSqlDriver::TableName ); |
103 inline static QString qTableName( const QString& prefix, QSqlDriver* driver ) |
|
104 { |
|
105 return driver->escapeIdentifier( prefix + "_" + qGetHostName(), QSqlDriver::TableName ); |
104 } |
106 } |
105 |
107 |
106 inline static bool testWhiteSpaceNames( const QString &name ) |
108 inline static bool testWhiteSpaceNames( const QString &name ) |
107 { |
109 { |
108 /* return name.startsWith( "QPSQL" ) |
110 /* return name.startsWith( "QPSQL" ) |
248 addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") ); |
250 addDb( "QSQLITE", QDir::toNativeSeparators(QDir::tempPath()+"/foo.db") ); |
249 // addDb( "QSQLITE2", QDir::toNativeSeparators(QDir::tempPath()+"/foo2.db") ); |
251 // addDb( "QSQLITE2", QDir::toNativeSeparators(QDir::tempPath()+"/foo2.db") ); |
250 // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.nokia.troll.no\\ICEBLINK", "troll", "trond", "" ); |
252 // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=iceblink.nokia.troll.no\\ICEBLINK", "troll", "trond", "" ); |
251 // addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.nokia.troll.no\\SQLEXPRESS", "troll", "trond", "" ); |
253 // addDb( "QODBC3", "DRIVER={SQL Native Client};SERVER=silence.nokia.troll.no\\SQLEXPRESS", "troll", "trond", "" ); |
252 |
254 |
253 // addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=mysql5-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); |
255 // addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=bq-mysql50.apac.nokia.com;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); |
254 // addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=mysql4-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); |
256 // addDb( "QODBC", "DRIVER={MySQL ODBC 5.1 Driver};SERVER=bq-mysql51.apac.nokia.com;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); |
255 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=horsehead.nokia.troll.no;DATABASE=testdb;PORT=4101;UID=troll;PWD=trondk", "troll", "trondk", "" ); |
257 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=horsehead.nokia.troll.no;DATABASE=testdb;PORT=4101;UID=troll;PWD=trondk", "troll", "trondk", "" ); |
256 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=silence.nokia.troll.no;DATABASE=testdb;PORT=2392;UID=troll;PWD=trond", "troll", "trond", "" ); |
258 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=silence.nokia.troll.no;DATABASE=testdb;PORT=2392;UID=troll;PWD=trond", "troll", "trond", "" ); |
257 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433;UID=testuser;PWD=Ee4Gabf6_;TDS_Version=8.0", "", "", "" ); |
259 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433;UID=testuser;PWD=Ee4Gabf6_;TDS_Version=8.0", "", "", "" ); |
258 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=bq-winserv2008-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433;UID=testuser;PWD=Ee4Gabf6_;TDS_Version=8.0", "", "", "" ); |
260 // addDb( "QODBC", "DRIVER={FreeTDS};SERVER=bq-winserv2008-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433;UID=testuser;PWD=Ee4Gabf6_;TDS_Version=8.0", "", "", "" ); |
259 // addDb( "QTDS7", "testdb", "testuser", "Ee4Gabf6_", "bq-winserv2003" ); |
261 // addDb( "QTDS7", "testdb", "testuser", "Ee4Gabf6_", "bq-winserv2003" ); |
260 // addDb( "QTDS7", "testdb", "testuser", "Ee4Gabf6_", "bq-winserv2008" ); |
262 // addDb( "QTDS7", "testdb", "testuser", "Ee4Gabf6_", "bq-winserv2008" ); |
261 // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); |
263 // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); |
262 // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2008-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); |
264 // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2008-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); |
263 // addDb( "QODBC", "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dbs\\access\\testdb.mdb", "", "", "" ); |
265 // addDb( "QODBC", "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dbs\\access\\testdb.mdb", "", "", "" ); |
264 // addDb( "QODBC", "DRIVER={Postgresql};SERVER=postgres81-nokia.trolltech.com.au;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); |
266 // addDb( "QODBC", "DRIVER={Postgresql};SERVER=bq-pgsql84.apac.nokia.com;DATABASE=testdb", "testuser", "Ee4Gabf6_", "" ); |
265 } |
267 } |
266 |
268 |
267 void open() |
269 void open() |
268 { |
270 { |
269 addDbs(); |
271 addDbs(); |
336 |
338 |
337 if ( dbtables.contains( table, Qt::CaseInsensitive ) ) { |
339 if ( dbtables.contains( table, Qt::CaseInsensitive ) ) { |
338 foreach(const QString &table2, dbtables.filter(table, Qt::CaseInsensitive)) { |
340 foreach(const QString &table2, dbtables.filter(table, Qt::CaseInsensitive)) { |
339 if(table2.compare(table.section('.', -1, -1), Qt::CaseInsensitive) == 0) { |
341 if(table2.compare(table.section('.', -1, -1), Qt::CaseInsensitive) == 0) { |
340 table=db.driver()->escapeIdentifier(table2, QSqlDriver::TableName); |
342 table=db.driver()->escapeIdentifier(table2, QSqlDriver::TableName); |
341 if(db.driverName().startsWith( "QPSQL" )) |
343 if(isPostgreSQL(db)) |
342 wasDropped = q.exec( "drop table " + table + " cascade"); |
344 wasDropped = q.exec( "drop table " + table + " cascade"); |
343 else |
345 else |
344 wasDropped = q.exec( "drop table " + table); |
346 wasDropped = q.exec( "drop table " + table); |
345 dbtables.removeAll(table2); |
347 dbtables.removeAll(table2); |
346 } |
348 } |
481 return db.databaseName().contains( "Access Driver", Qt::CaseInsensitive ); |
483 return db.databaseName().contains( "Access Driver", Qt::CaseInsensitive ); |
482 } |
484 } |
483 |
485 |
484 static bool isPostgreSQL( QSqlDatabase db ) |
486 static bool isPostgreSQL( QSqlDatabase db ) |
485 { |
487 { |
486 return db.driverName().startsWith("QPSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("PostgreSQL") ); |
488 return db.driverName().startsWith("QPSQL") || (db.driverName().startsWith("QODBC") && ( db.databaseName().contains("PostgreSQL", Qt::CaseInsensitive) || db.databaseName().contains("pgsql", Qt::CaseInsensitive) ) ); |
487 } |
489 } |
488 |
490 |
489 static bool isMySQL( QSqlDatabase db ) |
491 static bool isMySQL( QSqlDatabase db ) |
490 { |
492 { |
491 return db.driverName().startsWith("QMYSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("MySQL") ); |
493 return db.driverName().startsWith("QMYSQL") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("MySQL", Qt::CaseInsensitive) ); |
492 } |
494 } |
493 static bool isDB2( QSqlDatabase db ) |
495 static bool isDB2( QSqlDatabase db ) |
494 { |
496 { |
495 return db.driverName().startsWith("QDB2") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("db2") ); |
497 return db.driverName().startsWith("QDB2") || (db.driverName().startsWith("QODBC") && db.databaseName().contains("db2", Qt::CaseInsensitive) ); |
496 } |
498 } |
497 |
499 |
498 // -1 on fail, else Oracle version |
500 // -1 on fail, else Oracle version |
499 static int getOraVersion( QSqlDatabase db ) |
501 static int getOraVersion( QSqlDatabase db ) |
500 { |
502 { |