Pārlūkot izejas kodu

Show lack of database connection when none is desired.

Neal Wilson 7 gadus atpakaļ
vecāks
revīzija
11a12e269a
2 mainītis faili ar 101 papildinājumiem un 63 dzēšanām
  1. 76
    61
      config/Windows/navigation.xml
  2. 25
    2
      src/typica.w

+ 76
- 61
config/Windows/navigation.xml Parādīt failu

286
 			query.exec("CREATE OR REPLACE FUNCTION log_use() RETURNS trigger AS $$ DECLARE i integer := array_lower(NEW.unroasted_id, 1); u integer := array_upper(NEW.unroasted_id, 1); BEGIN IF NEW.transaction_type = 'ROAST' THEN WHILE i <= u LOOP INSERT INTO use (time, item, quantity) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i]); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
286
 			query.exec("CREATE OR REPLACE FUNCTION log_use() RETURNS trigger AS $$ DECLARE i integer := array_lower(NEW.unroasted_id, 1); u integer := array_upper(NEW.unroasted_id, 1); BEGIN IF NEW.transaction_type = 'ROAST' THEN WHILE i <= u LOOP INSERT INTO use (time, item, quantity) VALUES(NEW.time, NEW.unroasted_id[i], NEW.unroasted_quantity[i]); i := i + 1; END LOOP; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
287
 			query.exec("UPDATE TypicaFeatures SET version = 4 WHERE feature = 'base-features'");
287
 			query.exec("UPDATE TypicaFeatures SET version = 4 WHERE feature = 'base-features'");
288
 		};
288
 		};
289
-                var DBUpdateReminders = function() {
290
-                    var query = new QSqlQuery;
291
-                    query.exec("CREATE TABLE IF NOT EXISTS reminders (id bigserial PRIMARY KEY NOT NULL, reminder text NOT NULL)");
292
-                    query.exec("UPDATE TypicaFeatures SET version = 5 WHERE feature = 'base-features'");
293
-                    query = query.invalidate();
294
-                };
289
+        var DBUpdateReminders = function() {
290
+            var query = new QSqlQuery;
291
+            query.exec("CREATE TABLE IF NOT EXISTS reminders (id bigserial PRIMARY KEY NOT NULL, reminder text NOT NULL)");
292
+            query.exec("UPDATE TypicaFeatures SET version = 5 WHERE feature = 'base-features'");
293
+            query = query.invalidate();
294
+        };
295
 		var DBUpdateSpecification = function() {
295
 		var DBUpdateSpecification = function() {
296
-                    var query = new QSqlQuery;
297
-                    query.exec("CREATE TABLE IF NOT EXISTS roasting_specification (\"time\" timestamp without time zone NOT NULL, item bigint NOT NULL, loss numeric, tolerance numeric, notes text)");
298
-                    query.exec("UPDATE TypicaFeatures SET version = 6 WHERE feature = 'base-features'");
299
-                    query = query.invalidate();
300
-                };
301
-                
302
-		query = new QSqlQuery();
303
-		/* A table keeps track of database versioning information. This table is created
304
-		   if required. */
305
-		query.exec("CREATE TABLE IF NOT EXISTS TypicaFeatures (feature TEXT PRIMARY KEY, enabled boolean, version bigint)");
306
-		/* At the moment everything we're interested in is covered in the base-features
307
-		   row, but this can be extended later if needed. Each row encodes if certain
308
-		database structures exist and what version of those structures exist. */
309
-		query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'base-features'");
310
-		if(query.next())
311
-		{
312
-                    if(query.value(2) < 1)
313
-                    {
314
-                            DBCreateBase();
315
-                    }
316
-                    if(query.value(2) < 2)
317
-                    {
318
-                            DBUpdateMultiUser();
319
-                            DBUpdateHistory();
320
-                    }
321
-                    if(query.value(2) < 3)
322
-                    {
323
-                            DBUpdateNotifications();
324
-                    }
325
-                    if(query.value(2) < 4)
326
-                    {
327
-                            DBUpdateTriggers();
328
-                    }
329
-                    if(query.value(2) < 5)
330
-                    {
331
-                        DBUpdateReminders();
332
-                    }
333
-                    if(query.value(2) < 6)
334
-                    {
335
-                        DBUpdateSpecification();
336
-                    }
337
-		}
338
-		else
339
-		{
340
-			DBCreateBase();
341
-		}
342
-		query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
343
-		if(query.next())
344
-		{
345
-			if(query.value(2) < 1)
296
+            var query = new QSqlQuery;
297
+            query.exec("CREATE TABLE IF NOT EXISTS roasting_specification (\"time\" timestamp without time zone NOT NULL, item bigint NOT NULL, loss numeric, tolerance numeric, notes text)");
298
+            query.exec("UPDATE TypicaFeatures SET version = 6 WHERE feature = 'base-features'");
299
+            query = query.invalidate();
300
+        };
301
+		
302
+		/* Updates for Typica version 1.8 */
303
+		var DBUpdate18 = function() {
304
+			var query = new QSqlQuery;
305
+			/* Create a table for Typica users login data */
306
+			query.exec("CREATE TABLE IF NOT EXISTS typica_users(name TEXT PRIMARY KEY NOT NULL, password TEXT, active boolean NOT NULL, auto_login boolean NOT NULL)");
307
+			/* Update session user logging to only use the database user when a Typica user is not explicitly provided. This maintains compatibility for mixed version use. */
308
+			query.exec("CREATE OR REPLACE FUNCTION log_session_user() RETURNS trigger AS $$ BEGIN IF NEW.person IS NULL THEN NEW.person := session_user; END IF; RETURN NEW; END; $$ LANGUAGE plpgsql");
309
+			
310
+			/* Uncomment before release */
311
+			// query.exec("UPDATE TypicaFeatures SET version = 7 WHERE feature = 'base-features'");
312
+			query = query.invalidate();
313
+		};
314
+		if(Application.databaseConnected()) {
315
+			query = new QSqlQuery();
316
+			/* A table keeps track of database versioning information. This
317
+			   table is created
318
+			   if required. */
319
+			query.exec("CREATE TABLE IF NOT EXISTS TypicaFeatures (feature TEXT PRIMARY KEY, enabled boolean, version bigint)");
320
+			query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'sample-roasting'");
321
+			if(query.next())
322
+			{
323
+				if(query.value(2) < 1)
324
+				{
325
+					DBCreateSampleRoasting();
326
+				}
327
+			}
328
+			else
346
 			{
329
 			{
347
 				DBCreateSampleRoasting();
330
 				DBCreateSampleRoasting();
348
 			}
331
 			}
332
+			query.exec("SELECT feature, enabled, version FROM TypicaFeatures WHERE feature = 'base-features'");
333
+			if(query.next())
334
+			{
335
+				if(query.value(2) < 1)
336
+				{
337
+				        DBCreateBase();
338
+				}
339
+				if(query.value(2) < 2)
340
+				{
341
+			        DBUpdateMultiUser();
342
+			        DBUpdateHistory();
343
+				}
344
+				if(query.value(2) < 3)
345
+				{
346
+			        DBUpdateNotifications();
347
+				}
348
+				if(query.value(2) < 4)
349
+				{
350
+			        DBUpdateTriggers();
351
+				}
352
+				if(query.value(2) < 5)
353
+				{
354
+				    DBUpdateReminders();
355
+				}
356
+				if(query.value(2) < 6)
357
+				{
358
+					DBUpdateSpecification();
359
+				}
360
+				if(query.value(2) < 7) {
361
+					DBUpdate18();
362
+				}
363
+			}
364
+			else
365
+			{
366
+				DBCreateBase();
367
+			}
368
+			query = query.invalidate();
349
 		}
369
 		}
350
-		else
351
-		{
352
-			DBCreateSampleRoasting();
353
-		}
354
-		query = query.invalidate();
355
         ]]>
370
         ]]>
356
     </program>
371
     </program>
357
 </window>
372
 </window>

+ 25
- 2
src/typica.w Parādīt failu

1079
 ScriptQMainWindow::ScriptQMainWindow()@+: QMainWindow(NULL),
1079
 ScriptQMainWindow::ScriptQMainWindow()@+: QMainWindow(NULL),
1080
     cprompt(tr("Closing this window may result in loss of data. Continue?"))@/
1080
     cprompt(tr("Closing this window may result in loss of data. Continue?"))@/
1081
 {
1081
 {
1082
-    /* Nothing needs to be done here. */
1082
+    if(!AppInstance->databaseConnected())
1083
+    {
1084
+	    statusBar()->addWidget(new QLabel(tr("Not connected to database")));
1085
+    }
1083
 }
1086
 }
1084
 
1087
 
1085
 void ScriptQMainWindow::saveSizeAndPosition(const QString &key)
1088
 void ScriptQMainWindow::saveSizeAndPosition(const QString &key)
12822
         QDomDocument* configuration();
12825
         QDomDocument* configuration();
12823
         @<Device configuration members@>@;
12826
         @<Device configuration members@>@;
12824
         QSqlDatabase database();
12827
         QSqlDatabase database();
12828
+        Q_INVOKABLE bool databaseConnected();
12825
         QScriptEngine *engine;@/
12829
         QScriptEngine *engine;@/
12826
     @[public slots@]:@/
12830
     @[public slots@]:@/
12831
+	    void setDatabaseConnected(bool status);
12827
         @<Extended Application slots@>@;
12832
         @<Extended Application slots@>@;
12828
     private:@/
12833
     private:@/
12829
         @<Application private data members@>@;
12834
         @<Application private data members@>@;
12830
         QDomDocument conf;
12835
         QDomDocument conf;
12836
+        bool connectionStatus;
12831
 };
12837
 };
12832
 
12838
 
12833
 @ The constructor for this class handles a few things that had previously been
12839
 @ The constructor for this class handles a few things that had previously been
12834
 handled in |main()|.
12840
 handled in |main()|.
12835
 
12841
 
12836
 @<Application Implementation@>=
12842
 @<Application Implementation@>=
12837
-Application::Application(int &argc, char **argv) : QApplication(argc, argv)@/
12843
+Application::Application(int &argc, char **argv) : QApplication(argc, argv),
12844
+	connectionStatus(false)@/
12838
 {
12845
 {
12839
     @<Allow use of the default QSettings constructor@>@;
12846
     @<Allow use of the default QSettings constructor@>@;
12840
     @<Load translation objects@>@;
12847
     @<Load translation objects@>@;
12902
     return QSqlDatabase::cloneDatabase(connection, QString(connectionName));
12909
     return QSqlDatabase::cloneDatabase(connection, QString(connectionName));
12903
 }
12910
 }
12904
 
12911
 
12912
+@ Starting with version 1.8 there are methods for determining if a connection
12913
+to the database was successfully established when Typica was opened.
12914
+
12915
+@<Application Implementation@>=
12916
+void Application::setDatabaseConnected(bool status)
12917
+{
12918
+	connectionStatus = status;
12919
+}
12920
+
12921
+bool Application::databaseConnected()
12922
+{
12923
+	return connectionStatus;
12924
+}
12925
+
12905
 @** Table editor for ordered arrays with SQL relations.
12926
 @** Table editor for ordered arrays with SQL relations.
12906
 
12927
 
12907
 \noindent A database in use at Wilson's Coffee \char'046~Tea stores information
12928
 \noindent A database in use at Wilson's Coffee \char'046~Tea stores information
13786
         settings.setValue("database/user", user->text());
13807
         settings.setValue("database/user", user->text());
13787
         settings.setValue("database/password", password->text());
13808
         settings.setValue("database/password", password->text());
13788
         database.close();
13809
         database.close();
13810
+        AppInstance->setDatabaseConnected(true);
13789
         accept();
13811
         accept();
13790
     }
13812
     }
13791
     else
13813
     else
13825
 else
13847
 else
13826
 {
13848
 {
13827
     database.close();
13849
     database.close();
13850
+    AppInstance->setDatabaseConnected(true);
13828
 }
13851
 }
13829
 
13852
 
13830
 @** Viewing a record of batches.
13853
 @** Viewing a record of batches.

Notiek ielāde…
Atcelt
Saglabāt