Python Connector for Snowflake Module class - Python Connector for Snowflake |
The module
class provides methods, global properties, exceptions, constructors, and type objects to be used by all connections created in the module.
connect(connection string|connection parameters)
Creates a new connection to the database.
Arguments
connection string
"parameter=value;parameter=value"
connection parameters
Connection parameters
Return value
connection
object.Code sample
# establising a connection using a connection string
connection1 = devart.snowflake.connect("Domain=your_instance;UserId=your_username;Password=your_password;Database=your_database")
# establising a connection using named parameters
connection2 = devart.snowflake.connect(
Domain="your_instance;",
UserId="your_username",
Password="your_password",Database="your_database;"
)
license.activate(activation key)
Activates a license.
Arguments
activation key
Remarks
license.deactivate()
Deactivates a license.
Arguments
Remarks
apilevel
"2.0"
.threadsafety
2
meaning threads may share the module and connections.paramstyle
"named"
indicating that the module supports named style parameters, such as ...WHERE name=:name
.connection_pool
license.summary
Warning
Warning
exception is a subclass of the Python Exception
class.Error
except
statement. The Error
exception is a subclass of the Python Exception
class.InterfaceError
InterfaceError
exception is a subclass of Error
.DatabaseError
DatabaseError
exception is a subclass of Error
.DataError
DataError
exception is a subclass of DatabaseError
.OperationalError
DatabaseError
.IntegrityError
IntegrityError
exception is a subclass of DatabaseError
.InternalError
InternalError
exception is a subclass of DatabaseError
.ProgrammingError
ProgrammingError
exception is a subclass of DatabaseError
.NotSupportedError
rollback()
on a connection that doesn't support transactions or has transactions turned off. The NotSupportedError
exception is a subclass of DatabaseError
.Exception
Warning
Error
InterfaceError
DatabaseError
DataError
OperationalError
IntegrityError
InternalError
ProgrammingError
NotSupportedError
datetime
module objects.
Date(year, month, day)
Creates an object that holds a date value.
Arguments
year
month
day
int
that specify the year, month, and day.Return value
datetime.date
object.Time(hour, minute, second[, timezone])
Creates an object that holds a time value.
Arguments
hour
minute
int
that specify hours and minutes.second
int
value that specifies seconds or a float
value that specifies seconds and microseconds.timezone
datetime.tzinfo
that specifies a timezone. The value can be None
.Return value
datetime.time
object.Timestamp(year, month, day[, hour[, minute[, second[, timezone]]]])
Creates an object that holds a timestamp value.
Arguments
year
month
day
int
that specify the year, month, and day.hour
minute
int
that specify hours and minutes.second
int
value that specifies seconds or a float
value that specifies seconds and microseconds.timezone
datetime.tzinfo
that specifies a timezone. The value can be None
.Return value
datetime.datetime
object.DateFromTicks(ticks)
Creates an object that holds a date value from the given ticks value (the number of seconds since the Unix epoch). For more information, see the time
module in the standard Python documentation.
Arguments
ticks
float
that specifies number of seconds since the Unix epoch.Return value
datetime.date
object.TimeFromTicks(ticks)
Creates an object that holds a time value from the given ticks value (number of seconds since the Unix epoch). For more information, see the time
module in the standard Python documentation.
Arguments
ticks
float
that specifies number of seconds since the Unix epoch.Return value
datetime.time
object.TimestampFromTicks(ticks)
Creates an object that holds a timestamp value from the given ticks value (number of seconds since the Unix epoch). For more information, see the time
module in the standard Python documentation.
Arguments
ticks
float
that specifies number of seconds since the Unix epoch.Return value
datetime.datetime
object.Binary(value)
Creates an object that holds binary data.
addtypecast()
cursor method to define a data type cast rule to use when fetching data from the cursor. They can also be used to determine the Python types of the result columns returned by the execute*()
cursor methods.
STRING
This type object describes string-based columns in a database.
BINARY
This type object describes binary columns in a database.
NUMBER
This type object describes numeric columns in a database.
DATETIME
This type object describes date/time columns in a database.
ROWID
This type object describes the row ID
column in a database.
Code sample
cursor.execute("select column1 from table1")
# check if the first column in the result set is string-based so that its value can be safely treated as `str`
if cursor.description[0].type_code in snowflake.STRING:
# do something
binary
This type object describes an object that holds binary data. By default, this type object is used to fetch BLOB-based columns from the cursor. You can also create a binary
object using the Binary()
constructor.
Attributes
value
bytes
that represents binary data. This is a read/write attribute that accepts values of type str
, bytes
, bytearray
, array.array
, and binary
.