fix run, add connection check
This commit is contained in:
+11
-3
@@ -2,10 +2,11 @@ package utils
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -18,7 +19,8 @@ const (
|
||||
[tele_text] TEXT NOT NULL
|
||||
)
|
||||
`
|
||||
TableInsert = "insert into telegram (tele_text) values (?)"
|
||||
InsertNew = "insert into telegram (tele_text) values (?)"
|
||||
InsertOld = "insert into telegram (tele_text, tele_processed) values (?, 1)"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -69,7 +71,13 @@ func InsertTelegram(teleString string) {
|
||||
isWriting = true
|
||||
db := getDb()
|
||||
defer db.Close()
|
||||
stmt, err := db.Prepare(TableInsert)
|
||||
var insertSQL string
|
||||
if IsClientConnected() && WriteToClient(teleString) == nil {
|
||||
insertSQL = InsertOld
|
||||
} else {
|
||||
insertSQL = InsertNew
|
||||
}
|
||||
stmt, err := db.Prepare(insertSQL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user