Giter Site home page Giter Site logo

Comments (5)

griffio avatar griffio commented on September 26, 2024 1

@mcxinyu, LAST_INSERT_ID already exists, I had a go with a MySql version - see branch https://github.com/griffio/sqldelight-custom-dialect/tree/mysql
Seems to work ok - have a look and see if anything is different

from sqldelight.

mcxinyu avatar mcxinyu commented on September 26, 2024 1

@mcxinyu, LAST_INSERT_ID already exists, I had a go with a MySql version - see branch https://github.com/griffio/sqldelight-custom-dialect/tree/mysql Seems to work ok - have a look and see if anything is different

@griffio, Thank you so much, you gave me the correct answer.

image

from sqldelight.

griffio avatar griffio commented on September 26, 2024

Any functions that are not supported can be added here to the MySqlTypeResolver

private fun SqlFunctionExpr.mySqlFunctionType() = when (functionName.text.lowercase()) {

A work-around that may work for you, at this moment, could be to enclose the function in additional parentheses (). e.g

 INSERT INTO open_whitelists (userId, ip)
         VALUES (?, (INET_ATON(?))); 

This is valid in MySql and the SqlDelight compiler allows it as an expression without knowing the function.

from sqldelight.

mcxinyu avatar mcxinyu commented on September 26, 2024

Hello @griffio. It's really frustrating. I even referred to your sqldelight-custom-dialect project, but I did get an error prompt,

Compiling with dialect com.njf2016.sqldelight.MySqlCustomDialect

.../OpenWhitelists.sq: (18, 11): Unknown function LAST_INSERT_ID
18    SELECT LAST_INSERT_ID()
                 ^^^^^^^^^^^^^^^^

Here is the implementation of this class. Do you have any suggestions?

class MySqlCustomDialect : SqlDelightDialect by MySqlDialect() {
    override fun typeResolver(parentResolver: TypeResolver): TypeResolver {
        return MySqlTypeCustomResolver(parentResolver)
    }

    class MySqlTypeCustomResolver(private val parentResolver: TypeResolver) :
        TypeResolver by MySqlTypeResolver(parentResolver) {

        override fun functionType(functionExpr: SqlFunctionExpr): IntermediateType? {
            return when (functionExpr.functionName.text.lowercase()) {
                "inet_aton" -> IntermediateType(PrimitiveType.TEXT)
                "inet_ntoa" -> IntermediateType(PrimitiveType.TEXT)
                else -> parentResolver.functionType(functionExpr)
            }
        }
    }
}

from sqldelight.

mcxinyu avatar mcxinyu commented on September 26, 2024

At this point, the issue has been resolved, but I found that the sqldelight idea plugin seems to be abnormal.

20240314201928_rec_

from sqldelight.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.