gpkg-pg_loadpkg.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:PostgreSQL-GeoPackage 作者: EOX-A 项目源码 文件源码
def copy_table(conn_in, conn_out, table_name, constraint=None):
    cursor_in = conn_in.cursor()
    #Check that table exists
    cursor_in.execute(
        "SELECT name FROM sqlite_master WHERE type='table' AND name='%s';"
        % table_name
    )
    if cursor_in.fetchone():
        cursor_in.execute(
            "SELECT * FROM \"%s\"%s;" % (table_name, "" if constraint is None
                                         else " WHERE " + constraint)
        )

        with conn_out.cursor() as cursor_out:
            for record in cursor_in:
                values = record_to_string(record)
                try:
                    cursor_out.execute(
                        "INSERT INTO \"%s\" VALUES (%s);" %
                        (table_name, values)
                    )
                except psycopg2.IntegrityError as e:
                    conn_out.rollback()
                    if e.pgcode == '23505':
                        sys.stderr.write(
                            "ERROR: GeoPackage seems to be already imported. "
                            "Error message was: '%s'.\n" % e.message
                        )
                        sys.exit(1)
                except Exception as e:
                    conn_out.rollback()
                    sys.stderr.write(
                        "ERROR: Input doesn't seem to be a valid GeoPackage. "
                        "Error message was: '%s'.\n" % e.message
                    )
                    sys.exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号