Ejemplo n.º 1
0
 def execute_add_foreign_key(self, server):
     # self.params - (r_table, r_col, table)
     model_meta = ModelMeta(server, self.params[0])
     meta = model_meta.get_meta()
     try:
         refs = meta['REFERENCES']
     except KeyError:
         refs = []
     refs.append('%s=%s' % (self.params[1], self.params[2]))
     meta['REFERENCES'] = refs
     model_meta.set_meta(meta)
Ejemplo n.º 2
0
 def execute_create(self, server):
     # self.params --- (model opts, field_params)
     opts = self.params[0]
     meta = {}
     if opts.unique_together:
         meta['UNIQUE'] = list(opts.unique_together)
     for field, field_params in self.params[1].iteritems():
         params_list = []
         for param, value in field_params.iteritems():
             if value:
                 params_list.append(param)
         meta[field] = params_list
     model_meta = ModelMeta(server, opts.db_table)
     model_meta.set_meta(meta)
     # FIXME remove me
     # Creating database to not to break selects/inserts/whatever
     # temporary solution :)
     server.create(opts.db_table)
Ejemplo n.º 3
0
    def execute_insert(self, server, params):
        # self.params --- (table name, columns, values)
        table = server[self.params[0]]
        if not 'id' in self.params[1]:
            seq = Sequence(server, ("%s_seq"% (self.params[0], )))
            id = str(seq.nextval())
            obj = {'_id': id}
        else:
            obj = {}

        model_meta = ModelMeta(server, self.params[0])
        views = process_views(model_meta.get_meta(), self.params[1], self.params[2])
        for key, view, val in izip(self.params[1], views, params):
            if key=='id':
                key = '_id'
            if view == '__RAW__':
                obj[key] = val
            else:
                obj[key] = view % val
        table[obj['_id']] = obj
Ejemplo n.º 4
0
 def execute_update(self, server, params):
     # self.params --- (table name, column-values, where)
     table_name = self.params[0]
     table = server[table_name]
     view = self.simple_select(server, table, (table_name+'.'+'"id"',),
                               self.params[2], params)
     columns, values, views = [], [], []
     for col,val,v in self.params[1]:
         columns.append(unquote_name(col))
         values.append(val)
         views.append(v)
     model_meta = ModelMeta(server, self.params[0])
     views = process_views(model_meta.get_meta(), columns, views)
     for d in view:
         obj = table[d.id]
         for key, view, val in izip(columns, views, values):
             if key=='id':
                 key = '_id'
             if view == '__RAW__':
                 obj[key] = val
             else:
                 obj[key] = view % val
         table[obj['_id']] = obj