ConnectorTypeSQLMSSQL
class connector_types.connector_type_sqlmssql.ConnectorTypeSQLMSSQL
Interact with a MSSQL database. This connector type supports the execute,
fetchall, fetchone, and fetchval commands. Each command expects an
SQL query and returns the status, list, record or field value respectively.
Consult the Transact-SQL Reference at https://docs.microsoft.com/en-us/sql/t-sql/language-reference for more information.
Input Schema
-
schema_versionType:
string -
authenticationType:
anyOfOptions: -
hostThe remote hostname or IP address.
Type:
string -
portType:
anyOfOptions: -
instanceIf set, the
SQL Server Browseron port 1434 will be contacted to querythe TCP port of the named instance. The port returned by the
SQL Server Browserwilltake precedence to the one specified in the connection inputs.
Type:
string -
databaseType:
string -
modeType:
anyOfOptions: -
isolation_levelThe transaction isolation level.
Type:
anyOfOptions:Default:
READ_COMMITTED -
autocommitIf set to
Falsetransactions are enabled. Certain operations (e.g. CREATE DATABASE) requireautocommit=True.Type:
boolean -
fast_executemanyIf set to
Truetheexecutemanymethod will use thefast_executemanyflag. This is faster but might use subtly different datatype conversion.Type:
boolean -
connect_timeoutA timeout for connecting to a peer in seconds.
Type:
integerDefault:
30 -
total_timeoutTotal timeout for the request in seconds.
Type:
integerDefault:
30
Output Schema
Example
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
mssql_server_version = this.connect(
connector_type='SQLMSSQL',
authentication={
'authentication_method': 'username_password',
'username': '...',
'password': '...',
},
host='...',
mode={
'mode_name': 'fetchval',
'query': 'SELECT @@VERSION AS 'SQL Server Version';',
},
).get('output_value')['result']
this.log(mssql_server_version=mssql_server_version)
return this.success('all done')
More
Insert
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
this.connect(
connector_type='SQLMSSQL',
authentication={
'authentication_method': 'username_password',
'username': '...',
'password': '...',
},
host='...',
port={
'port_mode': 'port_number',
'port_number': 1433,
},
mode={
'mode_name': 'execute',
'query': 'INSERT INTO table (string_col, int_col) VALUES (?, ?)',
'params': [
'value1',
42,
],
},
)
return this.success('all done')
Bulk insert
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
this.connect(
connector_type='SQLMSSQL',
authentication={
'authentication_method': 'username_password',
'username': '...',
'password': '...',
},
host='...',
port={
'port_mode': 'service_name',
'service_name': 'ms-sql-s',
},
database='...',
mode={
'mode_name': 'executemany',
'query': 'INSERT INTO table (string_col, int_col) VALUES (?, ?)',
'rows': [
['value1', 42],
['value2', 4711],
],
'batch_size': 100,
},
)
return this.success('all done')
Transactions
import flow_api
def handler(system: flow_api.System, this: flow_api.Execution, inputs: dict):
results = this.connect(
connector_type='SQLMSSQL',
authentication={
'authentication_method': 'username_password',
'username': '...',
'password': '...',
},
host='...',
instance='...', # connect to named instance, look up the instance port
database='...',
mode={
'mode_name': 'transaction',
'queries': [
{
'mode_name': 'execute',
'query': 'INSERT INTO table (string_col, int_col) VALUES (?, ?)',
'params': [
'value1',
42,
],
},
{
'mode_name': 'fetchval',
'query': 'SELECT SCOPE_IDENTITY()',
},
],
},
).get('output_value')['result']
this.log(results=results)
return this.success('all done')