-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Started to implement the Driver, Connection, Statement and ResultSet class #45
base: main
Are you sure you want to change the base?
Conversation
…le to connect initially. Copied the TestUtils to the jdbc tests and added 2 dev-wise params Added the exception package for jdbc, could come in handy in the future
Started to implement some Parts of the connection and Driver to be able to connect initially. Copied the TestUtils to the jdbc tests and added 2 dev-wise params Added the exception package for jdbc, could come in handy in the future Implemented the connect method of the driver, getObject of the Statement and some other and the query method. Added a few tests for the SurrealJDBCDriverTest and SurrealJDBCStatementTest Still WIP.
It seems like the TestUtils class doesn't get the enviroment variables, I added a new task in the build.gradle called "jdbcTest", which is working. Don't really now how to fix it in the pipeline, does it take the config from the build.gradle? If yes we could add the vars here: |
JDBC Statement does only execute an SQL query without parameters. When using parameters a PreparedStatement must be created and the syntax of the query is defined: |
Generally speaking u are right, I will move this to the PreparedStatement. The JDBC Standard isn't covering this exactly, it's more like a EDIT: |
Did you finde, that it is possible to set parameters by parameter name? String sql = "SELECT * FROM your_table WHERE column1 = :param1 AND column2 = :param2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave this a quick read over and it looks really solid. Thanks for writing this Filip!
Regarding the above discussion - we can fix things and add functionality iteratively |
@flipflopsen could you have a look at the tests please? Do we need a separate task for them? They can run as part of normal driver |
@phughk |
What did I do?
Firstly I implemented the connect method of the SurrealJDBDriver which returns a SurrealJDBCConnection with params passed through a JDBC-Connection String which gets parsed into an URI for easier usage.
Furthermore the constrcutor of SurrealJDBCConnection is implemented which connects through the Websocket and Sync-/AsnycSurrealDriver with the database to establish an authenticated connection and uses a namespace and a dbName.
In addition to this I started to implement the executeQuery()-Method of the SurrealJDBCStatement with support of arbitrary queries (with params as well (see problems section)) and the executeUpdate()-Method.
In terms of classes, the SurrealJDBCResultSet got the next().Method and the getObject(int columnIndex, Class<?> type)-Method implemented, to retrieve objects which are getting instantiated via. the gson library.
Tests
SurrealJDBCStatementTest: executeQuery, executeQueryWithArgs, executeUpdate
SurrealJDBCDriverTest: connect
Problems
The biggest problem at the moment is the retrieval of objects with arguments because the executeQuery override of the Statement only accepts a raw SQL String as an input. As a workaround I used this scheme (you can see it in the code as well):
"select * from person where name.first = $firstName withargs [firstName, "Name"];
Another suggestion is the structure of the jdbc url: jdbc:surrealdb://host:port/dbname;namespace;optionalParam2=SomeValue2;
Would love to discuss these topics with you and appreciate any form of feedback!
Greetings