Procházet zdrojové kódy

Fix bug in item_history database function

Neal Wilson před 11 roky
rodič
revize
9aa111e02a
1 změnil soubory, kde provedl 11 přidání a 0 odebrání
  1. 11
    0
      config/Windows/navigation.xml

+ 11
- 0
config/Windows/navigation.xml Zobrazit soubor

@@ -271,6 +271,13 @@ type="push" />
271 271
 			query = query.invalidate();
272 272
 		};
273 273
 		
274
+		/* Bug fix for item_history */
275
+		var DBUpdateHistory = function() {
276
+			var query = new QSqlQuery;
277
+			query.exec("CREATE OR REPLACE FUNCTION item_history(bigint) RETURNS SETOF item_transaction_with_balance AS $$ DECLARE r item_transaction_with_balance; q numeric; BEGIN CREATE TEMPORARY TABLE working(time timestamp without time zone, item bigint, quantity numeric, cost numeric, vendor text, reason text, customer text, type text, balance numeric) ON COMMIT DROP; INSERT INTO working SELECT time, item, quantity, cost, vendor, reason, customer, type, NULL AS balance FROM all_transactions WHERE item = $1 ORDER BY time ASC; q := 0; FOR r IN SELECT time, item, quantity, cost, vendor, reason, customer, type, balance FROM working LOOP CASE r.type WHEN 'PURCHASE', 'MAKE' THEN q := q + r.quantity; WHEN 'INVENTORY' THEN q := r.quantity; WHEN 'USE', 'SALE', 'LOSS' THEN q := q - r.quantity; END CASE; r.balance := q; RETURN NEXT r; END LOOP; DROP TABLE working; RETURN; END; $$ LANGUAGE plpgsql");
278
+			query.exec("DROP FUNCTION calculate_inventory_balance()");
279
+		};
280
+		
274 281
 		query = new QSqlQuery();
275 282
 		/* A table keeps track of database versioning information. This table is created
276 283
 		   if required. */
@@ -288,6 +295,10 @@ type="push" />
288 295
 			if(query.value(2) < 2)
289 296
 			{
290 297
 				DBUpdateMultiUser();
298
+				DBUpdateHistory();
299
+				/* Update statistics for better planner performance. Doesn't need to be done
300
+				   often but nobody is doing this on their own. */
301
+				query.exec("ANALYZE");
291 302
 			}
292 303
 		}
293 304
 		else

Loading…
Zrušit
Uložit