func isNewCache(db *sqlite3.Conn, url, userId string) bool { query := fmt.Sprintf("SELECT id FROM notifications WHERE userid='%s' AND url='%s';", userId, url) _, err := db.Query(query) return err != nil }
func createDatabaseSchema(db *sqlite3.Conn) { query := "SELECT name FROM sqlite_master WHERE type='table' AND name='notifications';" _, err := db.Query(query) if err != nil { db.Exec("CREATE TABLE notifications (id INTEGER PRIMARY KEY AUTOINCREMENT, userid VARCHAR(36), url VARCHAR(256), title VARCHAR(256));") } }
// GetSimIds returns a list of all simulation ids in the cyclus database for // conn. func GetSimIds(conn *sqlite3.Conn) (ids []string, err error) { sql := "SELECT SimID FROM SimulationTimeInfo" var stmt *sqlite3.Stmt for stmt, err = conn.Query(sql); err == nil; err = stmt.Next() { var s string if err := stmt.Scan(&s); err != nil { return nil, err } ids = append(ids, s) } if err != io.EOF { return nil, err } return ids, nil }
func exists_message_table(dbh *sqlite3.Conn) int { sql := "SELECT name FROM sqlite_master WHERE type='table' AND name='message';" flag := 0 exists, err := dbh.Query(sql) if err == nil { if exists.Valid() { // fmt.Println("found message db file") flag = 1 } } return flag }
func get_message_from_db(dbh *sqlite3.Conn) { // datetime(message.date + 978307200, 'unixepoch', 'localtime') as m_date sql := `select chat.guid, message.text, message.date + 978307200 as m_date from chat, message where chat.account_id=message.account_guid order by chat.guid, message.date;` fmt.Println("Begin exporting ...") // fmt.Println(sql) sms_backup_file := get_backup_file() out_file, err := os.OpenFile(sms_backup_file, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) if err != nil { fmt.Println("open sms out file error") log.Fatal(err) } defer out_file.Close() row := make(sqlite3.RowMap) for data, err := dbh.Query(sql); err == nil; err = data.Next() { data.Scan(row) if str, ok := row["text"].(string); ok { date_now := row["m_date"].(int64) sms_time := time.Unix(date_now, 0) phone_number := get_phone_number(row["guid"]) sms := phone_number + " " + sms_time.String() + " " + str if _, err := out_file.WriteString(sms); err != nil { fmt.Println("write sms file error") log.Fatal(err) } if strings.EqualFold(runtime.GOOS, "windows") { out_file.WriteString("\r\n") } else { out_file.WriteString("\n") } } else { fmt.Println("interface to string error") fmt.Println(row) } } fmt.Println("Export OK") }