Skip to content
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

Postgresql support in Exposed #1

Closed
TCDooM opened this issue Nov 20, 2014 · 1 comment
Closed

Postgresql support in Exposed #1

TCDooM opened this issue Nov 20, 2014 · 1 comment

Comments

@TCDooM
Copy link

TCDooM commented Nov 20, 2014

Hi,
we are trying to make Exposed work with Postgresql... looks like the select and insert queries work, but the creat methods fail due to "show tables" commnad that is not supported...
Postgresql needs some other command for finding the existing tables...
can you please help, Thanks.

ok, fixef it, don't know if it's right but:

fun Table.exists (): Boolean {
val tableName = this.tableName
var sql = "show tables"
var resultSet:java.sql.ResultSet? = null
if (Session.get().vendor == DatabaseVendor.PostgreSQL) {
sql = "SELECT tablename FROM pg_catalog.pg_tables"
}
resultSet = Session.get().connection.createStatement()?.executeQuery(sql)

if (resultSet != null) {
    while (resultSet!!.next()) {
        val existingTableName = resultSet!!.getString(1)
        if (existingTableName?.equalsIgnoreCase(tableName) ?: false) {
            return true
        }
    }
}

return false

}

@sdeleuze
Copy link

👍 for that one, supporting MySQL/PostgreSQL/H2 databases would cover most user needs I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants