コード例 #1
0
def create_tab(vect, tab_name, cats, clsses, cols, training=None):
    cur = vect.table.conn.cursor()
    table = Table(tab_name, vect.table.conn)
    add_link = True
    if table.exist():
        print("Table <%s> already exist, will be removed." % tab_name)
        table.drop(cursor=cur)
        add_link = False
    print("Ceating a new table <%s>." % tab_name)
    table.create(cols, cursor=cur)
    export2sqlite(table, cats, clsses,
                  Table(training, vect.table.conn) if training else None)
    cur.close()
    if add_link:
        vect.dblinks.add(
            Link(layer=len(vect.dblinks) + 1, name=tab_name, table=tab_name))
コード例 #2
0
def make_new_table(vct, tname, cols=COLS, force=None):
    """Check/remove/create a new table"""
    msgr = get_msgr()
    force = overwrite() if force is None else force
    create_link = True
    # make a new table
    table = Table(tname, vct.table.conn)
    if table.exist():
        if any([table.name == l.table_name for l in vct.dblinks]):
            create_link = False
        msg = _("Table <%s> already exist and will be removed.")
        msgr.warning(msg % table.name)
        table.drop(force=force)
    table.create(cols)
    # fill the new table with the segment cats
    slct = vct.table.filters.select(vct.table.key)
    cur = vct.table.execute(slct.get_sql())
    table.insert(((cat[0], None) for cat in cur), many=True)
    table.conn.commit()
    return table, create_link