From 33592fbc4edff30fb8ba72e6068c44842f4af5f8 Mon Sep 17 00:00:00 2001 From: Worros Date: Wed, 18 Nov 2009 00:12:24 +0800 Subject: [PATCH] Add math function for sqlite - may still be broken --- pyfpdb/fpdb_db.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyfpdb/fpdb_db.py b/pyfpdb/fpdb_db.py index 27291d7f..f3dcd681 100644 --- a/pyfpdb/fpdb_db.py +++ b/pyfpdb/fpdb_db.py @@ -20,6 +20,7 @@ import os import re import sys import logging +import math from time import time, strftime from Exceptions import * @@ -53,6 +54,10 @@ class VARIANCE: def finalize(self): return float(var(self.store)) +class sqlitemath: + def mod(self, a, b): + return a%b + class fpdb_db: MYSQL_INNODB = 2 PGSQL = 3 @@ -148,6 +153,9 @@ class fpdb_db: , detect_types=sqlite3.PARSE_DECLTYPES ) sqlite3.register_converter("bool", lambda x: bool(int(x))) sqlite3.register_adapter(bool, lambda x: "1" if x else "0") + self.db.create_function("floor", 1, math.floor) + tmp = sqlitemath() + self.db.create_function("mod", 2, tmp.mod) if use_numpy: self.db.create_aggregate("variance", 1, VARIANCE) else: