Giter Site home page Giter Site logo

exposed-upsert's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

exposed-upsert's Issues

SqlLite: Invalid sql leads to ArrayIndexOutOfBoundsException

Stacktrace: https://pastebin.com/raw/XzKVWhuB

This is my upsert statement:

TileEntitiesTable.upsert(
    conflictColumn = TileEntitiesTable.uuid,
    
    insertBody = {
        val location = tileEntity.location
        
        it[uuid] = tileEntity.uuid
        it[world] = tileEntity.location.world!!.uid
        it[chunkX] = chunk.x
        it[chunkZ] = chunk.z
        it[x] = location.blockX
        it[y] = location.blockY
        it[z] = location.blockZ
        it[yaw] = tileEntity.armorStand.location.yaw
        it[type] = tileEntity.material.typeName
        it[data] = ExposedBlob(tileEntity.getData())
    },
    
    updateBody = {
        it[data] = ExposedBlob(tileEntity.getData())
    }
)

The above upsert statement generates this sql:

INSERT INTO tileEntities (chunkX, chunkZ, "data", "type", uuid, world, x, y, yaw, z) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ON CONFLICT("uuid") DO UPDATE SET "data"=EXCLUDED."data"

As you can see, the statement is invalid, there should be another question mark in the update statement after "data"=
This leads to an ArrayIndexOutOfBoundsException in CorePreparedStatement.java.

I fixed it in this commit: https://github.com/NichtStudioCode/exposed-upsert/commit/297be27e8ab2aad81c404676653f2d0320650271. This is obviously not a perfect solution, hence why I am not making a pull request.

Insert body breaks the order of fields

a) repository link at bottom of page https://androidrepo.com/repo/dzikoysk-exposed-upsert is still broken

b)
if I have non DAO exposed Tables, is your upsert supposed to work also?

I have DSL defined tables (non IdTables)

abstract class BaseTable(name: String) : Table(name) {
    val dtoModCount = long("dto_mod_count")
    val dtoOptimisticLockId = long("dto_optimistic_lock_id")
    val dtoCreationDate = timestamp("dto_creation_date")
    val dtoCreationUser = varchar("dto_creation_user", VARCHAR_MEDIUM)
    val dtoModDate = timestamp("dto_mod_date")
    val dtoModUser = varchar("dto_mod_user", VARCHAR_MEDIUM)
}

object IssuesTable : BaseTable(name = "ISSUES") {
    val key = varchar("key", VARCHAR_SMALL)
    val project = varchar("project", VARCHAR_SMALL)
    ...
    override val primaryKey = PrimaryKey(key, name = "PK_Issue_key")
    private fun upsertCommonFields(it: InsertStatement<Number>, table: IssuesTable, dto: Issue) {
        it[table.project] = dto.project
        ...
    fun upsert(dto: Issue) {
        IssuesTable.upsert(conflictColumn = IssuesTable.key,
            insertBody = {
                it[IssuesTable.key] = dto.key
                upsertCommonFields(it, this, dto)
                updateBaseDTOmetadata(it, this, dto)
            },
            updateBody = {
                upsertCommonFields(it, this, dto)
                updateBaseDTOmetadata(it, this, dto)
            }
        )
    }

insert works, but update totally confuses column names and the values to put into them.

Unable to use column with reserved words such as "user" as conflict column.

I have a table with a column named user (which contains an id referring to my own users table). In Postgres, user is a reserved word, which means it's required to put quotes around it when using it in SQL.

I have the following code:

UsageInfos.upsert(
    conflictColumn = UsageInfos.user,
    insertBody = {
        it[user] = id
        it[other] = "Value"
    },
    updateBody = {
        it[other] = "Value"
    }
)

Which results in the following SQL:
INSERT INTO usageinfos ("other", "user") VALUES ('Value', 86) ON CONFLICT(user) DO UPDATE SET "other"='Value'

Because CONFLICT(user) is missing quotes, this results in an error.

The correct SQL should be:
INSERT INTO usageinfos ("other", "user") VALUES ('Value', 86) ON CONFLICT("user") DO UPDATE SET "other"='Value'

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.