예제 #1
0
def executeSQL(sqllist):


    import os, subprocess

    from Database.Connection import Connection

    maquina = " -h 127.0.0.1 -p 5434"

    con2 = Connection()

    con = con2.getConnection()

    # Choose your PostgreSQL version here

    # os.environ['PATH'] += r';C:\Program Files\PostgreSQL\9.5\bin'
    # D:\usbgis\apps\postgresql93\bin

    os.environ['PATH'] += r';C:/usbgis/apps/postgresql93/bin'

    # http://www.postgresql.org/docs/current/static/libpq-envars.html
    os.environ['PGHOST'] = 'localhost'

    os.environ['PGPORT'] = '5432'
    os.environ['PGUSER'] = '******'
    os.environ['PGPASSWORD'] = '******'
    os.environ['PGDATABASE'] = 'roads'

    import Writes

    s = ""

    for x in sqllist:
        s = s + x + ";\n"

    logging.debug(" \n\n\n")
    logging.debug(" SSSSSSSSSSS")
    logging.debug(s)
    logging.debug(" \n\n\n")

    from Utils import Directory

    dir = Directory.getPathTempDir()

    file = dir + "sqltemporal2.txt"

    file_temp = dir + "errores.txt"

    Writes.writefile(file, s)


    logging.debug(" Coondection " + con.database)

    cmd = "psql -d " + con.database + " -U " + con.user + maquina + " < " + file + " >  " + file_temp + ""
    print cmd

    subprocess.call(cmd, shell=True)
예제 #2
0
import logging

import sys
sys.path
sys.path.append('D:/repositorydef/SeismicRisk/Database/Directory.py')

from Database import Directory
logdir = Directory.getPathTempDir()
filelog = logdir + "seismicrisk.log"
logging.basicConfig(filename=filelog, level=logging.DEBUG)
logging.debug('This message should go to the log file')


class Connection():

    host = ""
    port = ""
    user = ""
    password = ""
    database = ""

    from Database import Directory

    pathsql = Directory.getPathSqlDir()
    pathconfig = pathsql.replace("Database/SQL/", "config/")
    print("pathsql " + pathconfig)
    # sys.path.insert(0, "C:\Users\AG\.qgis2\python\plugins\SeismicRisk\Database\\")
    fileconfig = pathconfig + "config.ini"

    def __init__(self):
        #super(Connection, self).__init__()
예제 #3
0
import logging
import random
import Writes

from Database import Directory

path_denug = Directory.getPathTempDir() + "seismicrisk.log"
logging.basicConfig(filename=path_denug, level=logging.INFO)

from Database.Connection import Connection

import conectarpostgres


def populateValutazione(databasename):
    numberofstructures = calculatenumberofstructures(databasename)
    logging.debug("numberofstructures")
    logging.debug(numberofstructures)
    # get the active layer
    # layer = iface.activeLayer()
    '''
        init postgres
        http://gis.stackexchange.com/questions/86983/how-to-properly-establish-a-postgresql-connection-using-qgscredentials
        '''

    sqllist = []

    for idstructura in range(0, numberofstructures):
        for param in range(1, 15):
            x = random.sample([0, 1], 1)
            # z= random.sample([0,1], 1)