1
1
/**
2
- * DDBC - D DataBase Connector - abstraction layer for RDBMS access, with interface similar to JDBC.
3
- *
2
+ * DDBC - D DataBase Connector - abstraction layer for RDBMS access, with interface similar to JDBC.
3
+ *
4
4
* Source file ddbc/core.d.
5
5
*
6
6
* DDBC library attempts to provide implementation independent interface to different databases.
7
- *
7
+ *
8
8
* Set of supported RDBMSs can be extended by writing Drivers for particular DBs.
9
9
* Currently it only includes MySQL Driver which uses patched version of MYSQLN (native D implementation of MySQL connector, written by Steve Teale)
10
- *
10
+ *
11
11
* JDBC documentation can be found here:
12
12
* $(LINK http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/package-summary.html)$(BR)
13
13
*
14
14
* Limitations of current version: readonly unidirectional resultset, completely fetched into memory.
15
- *
15
+ *
16
16
* Its primary objects are:
17
17
* $(UL
18
18
* $(LI Driver: $(UL $(LI Implements interface to particular RDBMS, used to create connections)))
@@ -134,64 +134,64 @@ enum SqlType {
134
134
VARCHAR ,
135
135
}
136
136
137
-
138
- /**
139
- * The level of isolation between transactions. Various isolation levels provide tradeoffs between
140
- * performance, reproducibility, and interactions with other simultaneous transactions.
141
- *
142
- * The default transaction isolation level depends on the DB driver. For example:
143
- * - Postgresql: Defaults to READ_COMMITTED
144
- * - MySQL: Defaults to REPEATABLE_READ
145
- * - SQLite: Defaults to SERIALIZABLE
146
- *
147
- * Generally, `SELECT` statements do see the effects of previous `UPDATE` statements within the same
148
- * transaction, despite the fact that they are not yet committed. However, there can be differences
149
- * between database implementations depending on the transaction isolation level.
150
- */
151
- enum TransactionIsolation {
152
- /**
153
- * Transactions are not supported at all, thus there is no isolation.
154
- */
155
- NONE ,
156
-
157
- /**
158
- * Statements can read rows that have been modified by other transactions but are not yet
159
- * committed. High parallelism, but risks dirty reads, non-repeatable reads, etc.
160
- */
161
- READ_UNCOMMITTED ,
162
-
163
- /**
164
- * Statements cannot read data that has been modified by other transactions but not yet
165
- * committed. However, data can be changed when other transactions are commited between statements
166
- * of a transaction resulting in non-repeatable reads or phantom data.
167
- */
168
- READ_COMMITTED ,
169
-
170
- /**
171
- * Shared locks are used to prevent modification of data read by transactions, preventing dirty
172
- * reads and non-repeatable reads. However, new data can be inserted, causing transactions to
173
- * potentially behave differently if the transaction is retried, i.e. "phantom reads".
174
- */
175
- REPEATABLE_READ ,
176
-
177
- /**
178
- * Locks are used to make sure transactions using the same data cannot run simultaneously. This
179
- * prevents dirty reads, non-repeatable reads, and phantom reads. However, this transaction
180
- * isolation level has the worst performance.
181
- */
182
- SERIALIZABLE ,
183
- }
184
-
185
- /**
186
- * A connection represents a session with a specific database. Within the context of a Connection,
187
- * SQL statements are executed and results are returned.
188
- *
189
- * Note: By default the Connection automatically commits changes after executing each statement. If
190
- * auto commit has been disabled, an explicit commit must be done or database changes will not be
191
- * saved.
192
- *
193
- * See_Also: https://docs.oracle.com/cd/E13222_01/wls/docs45/classdocs/java.sql.Connection.html
194
- */
137
+
138
+ /**
139
+ * The level of isolation between transactions. Various isolation levels provide tradeoffs between
140
+ * performance, reproducibility, and interactions with other simultaneous transactions.
141
+ *
142
+ * The default transaction isolation level depends on the DB driver. For example:
143
+ * - Postgresql: Defaults to READ_COMMITTED
144
+ * - MySQL: Defaults to REPEATABLE_READ
145
+ * - SQLite: Defaults to SERIALIZABLE
146
+ *
147
+ * Generally, `SELECT` statements do see the effects of previous `UPDATE` statements within the same
148
+ * transaction, despite the fact that they are not yet committed. However, there can be differences
149
+ * between database implementations depending on the transaction isolation level.
150
+ */
151
+ enum TransactionIsolation {
152
+ /**
153
+ * Transactions are not supported at all, thus there is no isolation.
154
+ */
155
+ NONE ,
156
+
157
+ /**
158
+ * Statements can read rows that have been modified by other transactions but are not yet
159
+ * committed. High parallelism, but risks dirty reads, non-repeatable reads, etc.
160
+ */
161
+ READ_UNCOMMITTED ,
162
+
163
+ /**
164
+ * Statements cannot read data that has been modified by other transactions but not yet
165
+ * committed. However, data can be changed when other transactions are commited between statements
166
+ * of a transaction resulting in non-repeatable reads or phantom data.
167
+ */
168
+ READ_COMMITTED ,
169
+
170
+ /**
171
+ * Shared locks are used to prevent modification of data read by transactions, preventing dirty
172
+ * reads and non-repeatable reads. However, new data can be inserted, causing transactions to
173
+ * potentially behave differently if the transaction is retried, i.e. "phantom reads".
174
+ */
175
+ REPEATABLE_READ ,
176
+
177
+ /**
178
+ * Locks are used to make sure transactions using the same data cannot run simultaneously. This
179
+ * prevents dirty reads, non-repeatable reads, and phantom reads. However, this transaction
180
+ * isolation level has the worst performance.
181
+ */
182
+ SERIALIZABLE ,
183
+ }
184
+
185
+ /**
186
+ * A connection represents a session with a specific database. Within the context of a Connection,
187
+ * SQL statements are executed and results are returned.
188
+ *
189
+ * Note: By default the Connection automatically commits changes after executing each statement. If
190
+ * auto commit has been disabled, an explicit commit must be done or database changes will not be
191
+ * saved.
192
+ *
193
+ * See_Also: https://docs.oracle.com/cd/E13222_01/wls/docs45/classdocs/java.sql.Connection.html
194
+ */
195
195
interface Connection : DialectAware {
196
196
// / Releases this Connection object's database and JDBC resources immediately instead of waiting for them to be automatically released.
197
197
void close ();
@@ -214,21 +214,21 @@ interface Connection : DialectAware {
214
214
Statement createStatement ();
215
215
// / Creates a PreparedStatement object for sending parameterized SQL statements to the database.
216
216
PreparedStatement prepareStatement (string query);
217
-
218
- /**
219
- * Returns the currently active transaction isolation level used by the DB connection.
220
- */
221
- TransactionIsolation getTransactionIsolation ();
222
-
223
- /**
224
- * Attempt to change the Transaction Isolation Level used for transactions, which controls how
225
- * simultaneous transactions will interact with each other. In general, lower isolation levels
226
- * require fewer locks and have better performanc, but also have fewer guarantees for
227
- * consistency.
228
- *
229
- * Note: setTransactionIsolation cannot be called while in the middle of a transaction.
230
- */
231
- void setTransactionIsolation (TransactionIsolation level);
217
+
218
+ /**
219
+ * Returns the currently active transaction isolation level used by the DB connection.
220
+ */
221
+ TransactionIsolation getTransactionIsolation ();
222
+
223
+ /**
224
+ * Attempt to change the Transaction Isolation Level used for transactions, which controls how
225
+ * simultaneous transactions will interact with each other. In general, lower isolation levels
226
+ * require fewer locks and have better performanc, but also have fewer guarantees for
227
+ * consistency.
228
+ *
229
+ * Note: setTransactionIsolation cannot be called while in the middle of a transaction.
230
+ */
231
+ void setTransactionIsolation (TransactionIsolation level);
232
232
}
233
233
234
234
interface ResultSetMetaData {
@@ -349,18 +349,19 @@ interface DataSetWriter {
349
349
350
350
interface ResultSet : DataSetReader {
351
351
void close ();
352
+ // / Will return true if the ResultSet is pointing at the first row
352
353
bool first ();
353
354
bool isFirst ();
354
355
bool isLast ();
355
356
bool next ();
356
357
357
- // Retrieves the number, types and properties of this ResultSet object's columns
358
+ // / Retrieves the number, types and properties of this ResultSet object's columns
358
359
ResultSetMetaData getMetaData ();
359
- // Retrieves the Statement object that produced this ResultSet object.
360
+ // / Retrieves the Statement object that produced this ResultSet object.
360
361
Statement getStatement ();
361
- // Retrieves the current row number
362
+ // / Retrieves the current row number
362
363
int getRow ();
363
- // Retrieves the fetch size for this ResultSet object.
364
+ // / Retrieves the fetch size for this ResultSet object.
364
365
deprecated (" Marked for removal as Cannot be used by all supported drivers. See Github issue #85" )
365
366
ulong getFetchSize ();
366
367
@@ -436,7 +437,7 @@ interface Statement : DialectAware {
436
437
void close ();
437
438
}
438
439
439
- // / An object that represents a precompiled SQL statement.
440
+ // / An object that represents a precompiled SQL statement.
440
441
interface PreparedStatement : Statement , DataSetWriter {
441
442
// / Executes the SQL statement in this PreparedStatement object, which must be an SQL INSERT, UPDATE or DELETE statement; or an SQL statement that returns nothing, such as a DDL statement.
442
443
int executeUpdate ();
@@ -495,7 +496,7 @@ string makeDDBCUrl(string driverName, string[string] params) {
495
496
}
496
497
497
498
// / Helper function to make url in form driverName://host:port/dbname?param1=value1,param2=value2
498
- string makeDDBCUrl (string driverName, string host = null , int port = 0 ,
499
+ string makeDDBCUrl (string driverName, string host = null , int port = 0 ,
499
500
string dbName = null , string [string ] params = null ) {
500
501
import std.algorithm.searching : canFind;
501
502
enforce(canFind([" sqlite" , " postgresql" , " mysql" , " sqlserver" , " oracle" , " odbc" ], driverName), " driver must be one of sqlite|postgresql|mysql|sqlserver|oracle|odbc" );
@@ -593,4 +594,4 @@ private unittest {
593
594
594
595
string url = makeDDBCUrl(" odbc" , params);
595
596
assert (url == " odbc://?dsn=myDSN" , " ODBC URL is not correct: " ~ url);
596
- }
597
+ }
0 commit comments