コード例 #1
0
import psycopg2
from mobilitydb.psycopg import register
from mobilitydb.examples.db_connect import psycopg_connect

connection = None

try:
    # Set the connection parameters to PostgreSQL
    connection = psycopg_connect()
    connection.autocommit = True

    # Register MobilityDB data types
    register(connection)

    cursor = connection.cursor()

    ######################
    # TBoolInst
    ######################

    select_query = "select * from tbl_tboolinst order by k limit 10"

    cursor.execute(select_query)
    print("\n****************************************************************")
    print("Selecting rows from tbl_tboolinst table\n")
    rows = cursor.fetchall()

    for row in rows:
        print("key =", row[0])
        print("tboolinst =", row[1])
        if not row[1]:
コード例 #2
0
import pytest
import psycopg2
import os
from mobilitydb import *
from mobilitydb.psycopg import register

db = psycopg2.connect(dbname=os.getenv('PGDATABASE', 'test'))
db.autocommit = True

register(db)
cur = db.cursor()

time_types = [TimestampSet, Period, PeriodSet]
box_types = [TBox, STBox]
duration_suffixes = ['Inst', 'I', 'Seq', 'S']
duration_types = ['INSTANT', 'INSTANTSET', 'SEQUENCE', 'SEQUENCESET']
temporal_types = [TBool, TInt, TFloat, TText, TGeomPoint, TGeogPoint]

def pytest_configure():
    for time in time_types:
        cur.execute(
            'CREATE TABLE IF NOT EXISTS tbl_' + time.__name__.lower() +
            '(timetype ' +  time.__name__.lower() + ' NOT NULL);')
    for box in box_types:
        cur.execute(
            'CREATE TABLE IF NOT EXISTS tbl_' + box.__name__.lower() +
            '(box ' +  box.__name__.lower() + ' NOT NULL);')
    for ttype in temporal_types:
        for suffix, duration in zip(duration_suffixes, duration_types):
            cur.execute(
                'CREATE TABLE IF NOT EXISTS tbl_' + ttype.__name__.lower() + suffix +