Class __builtin.Sql.Connection

Inheritance graph
Description

This class is the base class for connections to SQL servers. It is a generic interface on top of which the DB server specific implement their specifics.

This class thus serves as an interface guideline for the DB server specific connection classes.

Untyped and typed mode

The query results are returned in different ways depending on the query functions used: The ..typed_query functions select typed mode, while the other query functions uses the older untyped mode.

  • In untyped mode, all values except SQL NULL are returned as strings in their display representation, and SQL NULL is returned as zero.

  • In typed mode, values are returned in pike native form where it works well. That means at least that SQL integer fields are returned as pike integers, floats as floats, SQL NULL as Val.null, and of course strings still as strings. The representation of other SQL types depends on the capabilities of the server specific backends. It's also possible that floats in some cases are represented in other ways if too much precision is lost in the conversion to pike floats.

Note

For historical reasons, there may be server specific backends that operate differently from what is described here, e.g. some that return a bit of typed data in untyped mode.

Note

Typed operation was not supported at all prior to Pike 7.8.363, and may not be supported for all databases.

See also

Sql.Connection, Sql.Sql(), Result


Variable case_convert

bool __builtin.Sql.Connection.case_convert

Description

Convert all field names in mappings to lower_case. Only relevant to databases which only implement big_query(), and use upper/mixed-case fieldnames (eg Oracle).

0

No (default)

1

Yes


Variable master_sql

__deprecated__ this_program __builtin.Sql.Connection.master_sql

Description

Compatibility interface.

This used to be a variable containing the server specific connection object used for the actual SQL queries.

As the wrapper no longer exists, this symbol now just evaluates to the object.

Note

Read only


Method create

__builtin.Sql.Connection __builtin.Sql.Connection(string host)
__builtin.Sql.Connection __builtin.Sql.Connection(string host, string db)
__builtin.Sql.Connection __builtin.Sql.Connection(string host, mapping(string:int|string) options)
__builtin.Sql.Connection __builtin.Sql.Connection(string host, string db, string user)
__builtin.Sql.Connection __builtin.Sql.Connection(string host, string db, string user, string password)
__builtin.Sql.Connection __builtin.Sql.Connection(string host, string db, string user, string password, mapping(string:int|string) options)

Description

Create a new SQL connection.

Parameter host
string

Connect to the server specified.

int(0)

Access through a UNIX-domain socket or similar.

Parameter db

Select this database.

Parameter user

User name to access the database as.

Parameter password

Password to access the database.

Parameter options

Optional mapping of options. See the SQL-database documentation for the supported options. (eg Mysql.mysql()->create()).

Note

This function is typically called via Sql.Sql().

Note

Support for options was added in Pike 7.3.

Note

The base class (__builtin.Sql.Connection) only has a prototype.

See also

Sql.Sql()