SQLCMD não está sendo executado corretamente por meio do Python no Bash Env

0

Sempre que eu executo os scripts abaixo

#!/usr/bin/env python
import subprocess
import sys, getopt


# DB info:
host = 
db=
user=
password=
# take the argument provided by user
UN=str(sys.argv[1])    
# SQL query to return user info + role

f_statement1 = """ set nocount on; set ansi_warnings off; 
SELECT 
pl.placement_id PID, pl.placement_name, p.partner_name Publisher, pc.description Platform_client, pit.description +'/'+ dt.description  Integration_Device
FROM placement pl 
JOIN partner p ON pl.partner_id = p.partner_id 
JOIN platform_client pc ON p.platform_client_id = pc.platform_client_id
JOIN placement_integration_type_assoc pita ON pl.placement_id = pita.placement_id 
JOIN placement_integration_type pit ON pita.placement_integration_type_id = pit.placement_integration_type_id
JOIN device_type dt ON pl.device_type_id = dt.device_type_id 
WHERE pit.active=1
AND pita.active=1 AND pl.placement_id = """ + str(UN)

f_statement2 = """ set nocount on; set ansi_warnings off; 
SELECT 
pl.max_ad_duration Seconds, c.abbreviation Country,
CASE WHEN passback_allowed=0 THEN 'GUARANTEED' ELSE 'PASSBACK' END AS Buy_Type, 
CASE WHEN pl.skippable=0 THEN 'Non-Skippable' ELSE 'Skippable' END AS Skippable,
CASE WHEN pl.active=1 THEN 'ACTIVE' ELSE 'NOT_ACTIVE' END AS Status
FROM placement pl 
JOIN country c ON pl.country_id = c.country_id
WHERE   pl.placement_id =""" + str(UN)

f_statement3 = """ set nocount on; set ansi_warnings off;
SELECT url_expression FROM AN_MAIN..placement_domain_whitelist
WHERE active=1 and placement_id =""" + str(UN)

# run the first query
print('\n')
print(color.UNDERLINE + color.BOLD + "Results for PID " + str(UN) + ":" + color.END)
results1=subprocess.call([r"/opt/mssql-tools/bin/sqlcmd.exe", "-S",host, "-U",user, "-P",password, "-d",db, "-Q",f_statement1, "-Y","30", "-s", "|" ], shell=True)
print('\n')
results1=subprocess.call([r"/opt/mssql-tools/bin/sqlcmd", "-S", host, "-U",user, "-P",password, "-d",db, "-Q", f_statement2, "-Y","30", "-s", "|" ], shell=True)
print('\n')
print(color.UNDERLINE + color.BOLD + "Whitelist for PID " + str(UN) + ":" + color.END)
print('\n')
results1=subprocess.call([r"/opt/mssql-tools/bin/sqlcmd", "-S", host, "-U",user, "-P",password, "-d",db, "-Q", f_statement3, "-Y","30", "-s", "|" ], shell=True)
print('\n')

O SQL é usado, mas não retorna a consulta no meu script, ele só retorna a seção de ajuda, um exemplo sendo

As perguntas que tenho aqui é como obter o SQLCMD para usar a consulta SQL que tenho em meus scripts Python, e existe algo que eu possa colocar em meu .bashrc ou .bash_profile para evitar que eu tenha que usar todo o local de onde sqlcmd.exe é?

    
por jhallvid 12.02.2018 / 14:32

0 respostas