コード例 #1
0
ファイル: ty_orm.py プロジェクト: Sukelluskello/MIDAS
    def update(self, data):
        """update is your basic update method"""
        data = to_ascii(data)
        if data is None:
            return None
        original_data = {}
        updated_data = {}
        for i in data:
            if i.startswith("_") and i != "_table" and i != "_id":
                original_data[i] = data[i]
            else:
                updated_data[i] = data[i]

        to_change = {}
        for i in updated_data:
            if i != "_table" and i != "_id":
                if updated_data[i] != original_data["_%s" % i]:
                    to_change[i] = updated_data[i]

        sql = "UPDATE \"%s\" SET" % data["_table"]

        if not to_change:
            return None

        for i in to_change:
            sql += " %s=?," % i

        sql = sql.strip(",")

        sql += " WHERE id = ?;"

        params = to_change.values()
        params.append(data["_id"])

        self.raw_sql(sql, params)
コード例 #2
0
ファイル: ty_orm.py プロジェクト: 5l1v3r1/MIDAS-1
    def update(self, data):
        """update is your basic update method"""
        data = to_ascii(data)
        if data is None:
            return None
        original_data = {}
        updated_data = {}
        for i in data:
            if i.startswith("_") and i != "_table" and i != "_id":
                original_data[i] = data[i]
            else:
                updated_data[i] = data[i]

        to_change = {}
        for i in updated_data:
            if i != "_table" and i != "_id":
                if updated_data[i] != original_data["_%s" % i]:
                    to_change[i] = updated_data[i]

        sql = "UPDATE \"%s\" SET" % data["_table"]

        if not to_change:
            return None

        for i in to_change:
            sql += " %s=?," % i

        sql = sql.strip(",")

        sql += " WHERE id = ?;"

        params = to_change.values()
        params.append(data["_id"])

        self.raw_sql(sql, params)
コード例 #3
0
ファイル: ty_orm.py プロジェクト: Sukelluskello/MIDAS
 def insert(self, table_name, data):
     """insert is your basic insertion method"""
     data = to_ascii(data)
     if data is None:
         return None
     sql = "INSERT INTO %s" % table_name
     sql += "(id, %s) VALUES" % ', '.join(data.keys())
     sql += "(NULL, "
     sql += ', '.join(['?'] * len(data.values()))
     sql = "%s);" % sql
     params = data.values()
     self.raw_sql(sql, params)
コード例 #4
0
ファイル: ty_orm.py プロジェクト: 5l1v3r1/MIDAS-1
 def insert(self, table_name, data):
     """insert is your basic insertion method"""
     data = to_ascii(data)
     if data is None:
         return None
     sql = "INSERT INTO %s" % table_name
     sql += "(id, %s) VALUES" % ', '.join(data.keys())
     sql += "(NULL, "
     sql += ', '.join(['?'] * len(data.values()))
     sql = "%s);" % sql
     params = data.values()
     self.raw_sql(sql, params)
コード例 #5
0
ファイル: ty_orm.py プロジェクト: Sukelluskello/MIDAS
 def delete(self, data):
     """delete is your basic deletion method"""
     data = to_ascii(data)
     if data is None:
         return None
     if type(data) == dict:
         sql = "DELETE FROM \"%s\" WHERE id = ?;" % data["_table"]
         self.raw_sql(sql, [data["_id"]])
         return
     elif type(data) == list:
         tables_and_ids = {}
         for i in data:
             table = i["_table"]
             if table not in tables_and_ids:
                 tables_and_ids[table] = []
             tables_and_ids[table].append(i["_id"])
         for k, j in tables_and_ids.iteritems():
             sql = "DELETE FROM \"%s\" WHERE id IN (%s);" % (
                 k,
                 ', '.join(['?']*len(j))
             )
             self.raw_sql(sql, j)
コード例 #6
0
ファイル: ty_orm.py プロジェクト: 5l1v3r1/MIDAS-1
 def delete(self, data):
     """delete is your basic deletion method"""
     data = to_ascii(data)
     if data is None:
         return None
     if isinstance(data, dict):
         sql = "DELETE FROM \"%s\" WHERE id = ?;" % data["_table"]
         self.raw_sql(sql, [data["_id"]])
         return
     elif isinstance(data, (list, tuple)):
         tables_and_ids = {}
         for i in data:
             table = i["_table"]
             if table not in tables_and_ids:
                 tables_and_ids[table] = []
             tables_and_ids[table].append(i["_id"])
         for k, j in tables_and_ids.iteritems():
             sql = "DELETE FROM \"%s\" WHERE id IN (%s);" % (
                 k,
                 ', '.join(['?']*len(j))
             )
             self.raw_sql(sql, j)