Skip to content

Commit 7b6669f

Browse files
authored
Update comments and doc to provide more details about ResultSet (#682)
1 parent 4446e22 commit 7b6669f

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/readJdbc.kt

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,24 @@ private fun isValid(sqlQuery: String): Boolean {
228228
}
229229

230230
/**
231-
* Reads the data from a [ResultSet] and converts it into a DataFrame.
231+
* Reads the data from a [ResultSet][java.sql.ResultSet] and converts it into a DataFrame.
232232
*
233-
* @param [resultSet] the [ResultSet] containing the data to read.
233+
* A [ResultSet][java.sql.ResultSet] object maintains a cursor pointing to its current row of data.
234+
* By default, a ResultSet object is not updatable and has a cursor that can only move forward.
235+
* Therefore, you can iterate through it only once, from the first row to the last row.
236+
*
237+
* For more details, refer to the official Java documentation on [ResultSet][java.sql.ResultSet].
238+
*
239+
* NOTE: Reading from the [ResultSet][java.sql.ResultSet] could potentially change its state.
240+
*
241+
* @param [resultSet] the [ResultSet][java.sql.ResultSet] containing the data to read.
242+
* Its state may be altered after the read operation.
234243
* @param [dbType] the type of database that the [ResultSet] belongs to.
235-
* @param [limit] the maximum number of rows to read from the [ResultSet].
244+
* @param [limit] the maximum number of rows to read from the [ResultSet][java.sql.ResultSet].
236245
* @param [inferNullability] indicates how the column nullability should be inferred.
237-
* @return the DataFrame generated from the [ResultSet] data.
246+
* @return the DataFrame generated from the [ResultSet][java.sql.ResultSet] data.
247+
*
248+
* [java.sql.ResultSet]: https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html
238249
*/
239250
public fun DataFrame.Companion.readResultSet(
240251
resultSet: ResultSet,
@@ -247,13 +258,25 @@ public fun DataFrame.Companion.readResultSet(
247258
}
248259

249260
/**
250-
* Reads the data from a [ResultSet] and converts it into a DataFrame.
261+
* Reads the data from a [ResultSet][java.sql.ResultSet] and converts it into a DataFrame.
251262
*
252-
* @param [resultSet] the [ResultSet] containing the data to read.
253-
* @param [connection] the connection to the database (it's required to extract the database type).
254-
* @param [limit] the maximum number of rows to read from the [ResultSet].
263+
* A [ResultSet][java.sql.ResultSet] object maintains a cursor pointing to its current row of data.
264+
* By default, a ResultSet object is not updatable and has a cursor that can only move forward.
265+
* Therefore, you can iterate through it only once, from the first row to the last row.
266+
*
267+
* For more details, refer to the official Java documentation on [ResultSet][java.sql.ResultSet].
268+
*
269+
* NOTE: Reading from the [ResultSet][java.sql.ResultSet] could potentially change its state.
270+
*
271+
* @param [resultSet] the [ResultSet][java.sql.ResultSet] containing the data to read.
272+
* Its state may be altered after the read operation.
273+
* @param [connection] the connection to the database (it's required to extract the database type)
274+
* that the [ResultSet] belongs to.
275+
* @param [limit] the maximum number of rows to read from the [ResultSet][java.sql.ResultSet].
255276
* @param [inferNullability] indicates how the column nullability should be inferred.
256-
* @return the DataFrame generated from the [ResultSet] data.
277+
* @return the DataFrame generated from the [ResultSet][java.sql.ResultSet] data.
278+
*
279+
* [java.sql.ResultSet]: https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html
257280
*/
258281
public fun DataFrame.Companion.readResultSet(
259282
resultSet: ResultSet,

docs/StardustDocs/topics/readSqlDatabases.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,18 @@ The versions with a limit parameter will only read up to the specified number of
246246
This function allows reading a ResultSet object from your SQL database
247247
and transforms it into an AnyFrame object.
248248

249+
A ResultSet object maintains a cursor pointing to its current row of data.
250+
By default, a ResultSet object is not updatable and has a cursor that moves forward only.
251+
Therefore, you can iterate it only once and only from the first row to the last row.
252+
253+
More details about ResultSet can be found in the [official Java documentation](https://docs.oracle.com/javase/8/docs/api/java/sql/ResultSet.html).
254+
255+
Note that reading from the ResultSet could potentially change its state.
256+
249257
The `dbType: DbType` parameter specifies the type of our database (e.g., PostgreSQL, MySQL, etc.),
250258
supported by a library.
251259
Currently, the following classes are available: `H2, MariaDb, MySql, PostgreSql, Sqlite`.
252260

253-
254261
```kotlin
255262
import org.jetbrains.kotlinx.dataframe.io.db.PostgreSql
256263
import java.sql.ResultSet

0 commit comments

Comments
 (0)