@@ -20,12 +20,11 @@ Run pip::
2020
2121 $ pip install firebird-driver
2222
23-
2423.. _setuptools: https://pypi.org/project/setuptools/
2524.. _PYPI: https://pypi.org/
2625.. _ctypes: http://docs.python.org/library/ctypes.html
2726.. _pip: https://pypi.org/project/pip/
28-
27+ .. _firebird-base: https://firebird-base.rtfd.io
2928
3029Quick-start Guide
3130*****************
@@ -37,49 +36,90 @@ comprehensive in its coverage of anything else.
3736The numerous advanced features of Firebird-driver are covered in another section of this
3837documentation, which is not in a tutorial format, though it is replete with examples.
3938
39+ Driver configuration
40+ ====================
41+
42+ The driver uses configuration built on top of `configuration system <firebird.base.config>`
43+ provided by `firebird-base`_ package. In addition to global settings, the configuration
44+ also includes the definition of connection parameters to Firebird servers and databases.
45+
46+ The default configuration connects to embedded server using direct/local connection method.
47+ To access remote servers and databases (or local ones through remote protocols), it's
48+ neccessary to adjust default configuration, or `register` them in configuration manager.
49+
50+ You can manipulate the configuration objects directly, or load configuration from files or
51+ strings (in `.ini-style` `ConfigParser` format).
4052
4153Connecting to a Database
4254========================
4355
56+ **Example 1:**
4457
45- **Example 1**
46-
47- A database connection is typically established with code such as this:
58+ A simple database connection is typically established with code such as this:
4859
4960.. sourcecode:: python
5061
5162 from firebird.driver import connect
5263
53- # The server is named 'bison'; the database file is at '/temp/test.db'.
54- con = connect(dsn='bison:/temp/test.db ', user='sysdba', password='pass ')
64+ # Attach to 'employee' database/alias using embedded server connection
65+ con = connect('employee ', user='sysdba', password='masterkey ')
5566
56- # Or, equivalently:
57- con = connect(host='bison', database='/temp/test.db',
58- user='sysdba', password='pass')
67+ # Attach to 'employee' database/alias using local server connection
68+ from firebird.driver import driver_config
69+ driver_config.server_defaults.host.value = 'localhost'
70+ con = connect('employee', user='sysdba', password='masterkey')
5971
72+ # Set 'user' and 'password' via configuration
73+ driver_config.server_defaults.user.value = 'SYSDBA'
74+ driver_config.server_defaults.password.value = 'masterkey'
75+ con = connect('employee')
6076
61- **Example 2**
77+ **Example 2: **
6278
63- Suppose we want to connect to the database in SQL Dialect 1 and specifying
64- UTF-8 as the character set of the connection :
79+ A database connection typically uses specific configuration, and is established with code
80+ such as this :
6581
6682.. sourcecode:: python
6783
68- from firebird.driver import connect
84+ from firebird.driver import connect, driver_config
6985
70- con = connect(
71- dsn='bison:/temp/test.db',
72- user='sysdba', password='pass',
73- dialect=1, # necessary for all dialect 1 databases
74- charset='UTF8' # specify a character set for the connection
75- )
86+ # Register Firebird server
87+ srv_cfg = """[local]
88+ host = localhost
89+ user = SYSDBA
90+ password = masterkey
91+ """
92+ driver_config.register_server('local', srv_cfg)
93+
94+ # Register database
95+ db_cfg = """[employee]
96+ server = local
97+ database = employee.fdb
98+ protocol = inet
99+ charset = utf8
100+ """
101+ driver_config.register_database('employee', db_cfg)
76102
103+ # Attach to 'employee' database
104+ con = connect('employee')
105+
106+ .. note::
107+
108+ Some parameters like 'user' and 'password' could be overriden with keyword parameters.
109+ Few parameters like 'crypt_callback' or 'no_db_triggers' could be specified **ONLY**
110+ as keyword arguments.
111+
112+ Creating a Database
113+ ===================
114+
115+ A database is created using `~firebird.driver.core.create_database()` function.
116+ Like `~firebird.driver.core.connect()`, this function uses configuration for specification of
117+ database parameters like page size, sweep interval etc.
77118
78119Executing SQL Statements
79120========================
80121
81- For this section, suppose we have a table defined and populated by the
82- following SQL code:
122+ For this section, suppose we have a table defined and populated by the following SQL code:
83123
84124.. sourcecode:: sql
85125
@@ -92,7 +132,6 @@ following SQL code:
92132 insert into languages (name, year_released) values ('C', 1972);
93133 insert into languages (name, year_released) values ('Python', 1991);
94134
95-
96135**Example 1**
97136
98137This example shows the *simplest* way to print the entire contents of
@@ -102,7 +141,7 @@ the `languages` table:
102141
103142 from firebird.driver import connect
104143
105- con = connect(database='/temp/ test.db ', user='sysdba', password='masterkey')
144+ con = connect(' test.fdb ', user='sysdba', password='masterkey')
106145
107146 # Create a Cursor object that operates in the context of Connection con:
108147 cur = con.cursor()
@@ -113,14 +152,12 @@ the `languages` table:
113152 # Retrieve all rows as a sequence and print that sequence:
114153 print(cur.fetchall())
115154
116-
117155Sample output:
118156
119157.. sourcecode:: python
120158
121159 [('C', 1972), ('Python', 1991)]
122160
123-
124161**Example 2**
125162
126163Here's another trivial example that demonstrates various ways of fetching a single row at a time from a `SELECT`-cursor:
@@ -129,7 +166,7 @@ Here's another trivial example that demonstrates various ways of fetching a sing
129166
130167 from firebird.driver import connect
131168
132- con = connect(dsn='/temp/ test.db ', user='sysdba', password='masterkey')
169+ con = connect(' test.fdb ', user='sysdba', password='masterkey')
133170
134171 cur = con.cursor()
135172 SELECT = "select name, year_released from languages order by year_released"
@@ -145,8 +182,6 @@ Here's another trivial example that demonstrates various ways of fetching a sing
145182 for row in cur:
146183 print(f'{row[0]} has been publicly available since {row[1]}.')
147184
148-
149-
150185Sample output:
151186
152187.. sourcecode:: python
@@ -158,7 +193,6 @@ Sample output:
158193 C has been publicly available since 1972.
159194 Python has been publicly available since 1991.
160195
161-
162196**Example 3**
163197
164198The following program is a simplistic table printer (applied in this example to `languages`):
@@ -170,7 +204,7 @@ The following program is a simplistic table printer (applied in this example to
170204 TABLE_NAME = 'languages'
171205 SELECT = f'select * from {TABLE_NAME} order by year_released'
172206
173- con = connect(dsn='/temp/ test.db ', user='sysdba', password='masterkey')
207+ con = connect(' test.fdb ', user='sysdba', password='masterkey')
174208
175209 cur = con.cursor()
176210 cur.execute(SELECT)
@@ -212,7 +246,7 @@ Let's insert more languages:
212246
213247 from firebird.driver import connect
214248
215- con = connect(dsn='/temp/ test.db ', user='sysdba', password='masterkey')
249+ con = connect(' test.fdb ', user='sysdba', password='masterkey')
216250
217251 cur = con.cursor()
218252
0 commit comments