question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce generatedKey() on SqlResult

See original GitHub issue

For PostgreSQL we can use RETURNING clause for fetching the generated keys, but in MySQL we can get the generated key via the last_insert_id in the OK_Packet OTTB, so we may add an interface for this in the sqlclient module for better usage.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vietjcommented, Aug 12, 2019

I am worried that each database will have its peculiarities

Perhaps we can add notion of properties on SqlResult , to do something like result.property("lastInsertId") ?

we could also do the same using generics magic to avoid casting and expose constants with something like:

@VertxGen
interface SqlResultProperty<T> {
}
@VertxGen
interface SqlResult {
  ...
  <T> T property(SqlResultProperty<T> property);
  ...
}
@VertxGen
interface MySQLClient extends SqlClient {
  // Constant
   SqlResultProperty<Integer> LAST_INSERTED_ID = new SqlResultPropertyImpl<>();
}
1reaction
BillyYccccommented, Aug 11, 2019

I agree we should avoid magic like injecting RETURNING clause into the SQL statement.

Since we use the same interface to represent the result as SqlResult, what I mean is adding a lastInsertId() method to the SqlResult interface.

  • For MySQL we can return the id with the value from OK_Packet natively.
  • For PostgreSQL we throw an UnsupportedOperation and give a hint to the users that they should write RETURNING SQL by themselves.
Read more comments on GitHub >

github_iconTop Results From Across the Web

The <generatedKey> Element - MyBatis Generator Core
The <generatedKey> element is used to specify properties for auto generated keys (from identity field or sequences).
Read more >
coldfusion - Missing GENERATEDKEY from Query Result
But I am just trying to determine why current code stopped working. I believed that generatedkey will always be returned for sql server...
Read more >
cfquery - Adobe Support
ColdFusion 9.0.1: Introduced support for HQL queries; added the attribute {{ormoptions. ... GENERATEDKEY, Supports all databases.
Read more >
SQL Server Choose() function introduction and examples
Example 1: SQL Server CHOOSE() function with literal values. In this example, we use choose() function to return values from different index ...
Read more >
4. Spark SQL and DataFrames: Introduction to Built-in Data ...
To issue any SQL query, use the sql() method on the SparkSession instance, spark , such as spark.sql("SELECT * FROM myTableName") . All...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found