mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 21:42:48 +01:00
Fix ERROR: relation "txo_spending_info" does not exist
(#4323)
* Fix `ERROR: relation "txo_spending_info" does not exist` * Escape schema name Co-authored-by: Chris Stewart <stewart.chris1234@gmail.com>
This commit is contained in:
parent
341c712563
commit
059f2f5fac
1 changed files with 44 additions and 10 deletions
|
@ -10,8 +10,9 @@ import org.bitcoins.core.wallet.utxo._
|
|||
import org.bitcoins.crypto.DoubleSha256DigestBE
|
||||
import org.bitcoins.db.CRUDAutoInc
|
||||
import org.bitcoins.wallet.config._
|
||||
import slick.ast.{TableExpansion, TableNode}
|
||||
|
||||
import java.sql.SQLException
|
||||
import java.sql.{PreparedStatement, SQLException}
|
||||
import scala.concurrent.{ExecutionContext, Future}
|
||||
|
||||
case class SpendingInfoDAO()(implicit
|
||||
|
@ -574,17 +575,50 @@ case class SpendingInfoDAO()(implicit
|
|||
.map(_ => ts.map(_.copyWithState(TxoState.Reserved)))
|
||||
}
|
||||
|
||||
def createOutPointsIndexIfNeeded(): Future[Unit] = {
|
||||
val query =
|
||||
sqlu"CREATE UNIQUE INDEX IF NOT EXISTS utxo_outpoints ON txo_spending_info (tx_outpoint)"
|
||||
safeDatabase.run(query).map(_ => ())
|
||||
def createOutPointsIndexIfNeeded(): Future[Unit] = Future {
|
||||
withStatement(
|
||||
s"CREATE UNIQUE INDEX IF NOT EXISTS utxo_outpoints ON $fullTableName (tx_outpoint)") {
|
||||
st =>
|
||||
st.executeUpdate()
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
def hasDuplicates(): Future[Boolean] = {
|
||||
val query =
|
||||
sql"SELECT EXISTS (SELECT tx_outpoint, COUNT(*) FROM txo_spending_info GROUP BY tx_outpoint HAVING COUNT(*) > 1)"
|
||||
.as[Boolean]
|
||||
safeDatabase.run(query).map(_.headOption.getOrElse(false))
|
||||
def hasDuplicates(): Future[Boolean] = Future {
|
||||
withStatement(
|
||||
s"SELECT EXISTS (SELECT tx_outpoint, COUNT(*) FROM $fullTableName GROUP BY tx_outpoint HAVING COUNT(*) > 1)") {
|
||||
st =>
|
||||
val rs = st.executeQuery()
|
||||
try {
|
||||
if (rs.next()) {
|
||||
rs.getBoolean(1)
|
||||
} else false
|
||||
} finally rs.close()
|
||||
}
|
||||
}
|
||||
|
||||
private def fullTableName: String = {
|
||||
val tableNode = table.toNode
|
||||
.asInstanceOf[TableExpansion]
|
||||
.table
|
||||
.asInstanceOf[TableNode]
|
||||
tableNode.schemaName
|
||||
.map(schema => "\"" + schema + "\".")
|
||||
.getOrElse("") + tableNode.tableName
|
||||
}
|
||||
|
||||
private def withStatement[T](sql: String)(f: PreparedStatement => T): T = {
|
||||
val conn = database.source.createConnection()
|
||||
val autoCommit = conn.getAutoCommit
|
||||
conn.setAutoCommit(true)
|
||||
try {
|
||||
val st = conn.prepareStatement(sql)
|
||||
try f(st)
|
||||
finally st.close()
|
||||
} finally {
|
||||
conn.setAutoCommit(autoCommit)
|
||||
conn.close()
|
||||
}
|
||||
}
|
||||
|
||||
private def findScriptPubKeysAction(ids: Seq[Long]): DBIOAction[
|
||||
|
|
Loading…
Add table
Reference in a new issue