From 3fa9bf737351c75822476cfca00dd0fe778616db Mon Sep 17 00:00:00 2001 From: Azareal Date: Sun, 5 Nov 2017 09:55:34 +0000 Subject: [PATCH] I've revamped the query generator to reduce the number of globals, this'll help us split up the software and plugins in the future. Refactored the router. Added the MemberOnly middleware and tests for it. --- alerts.go | 4 +- auth.go | 2 +- database.go | 5 + extend.go | 2 +- forum.go | 2 +- forum_perms_store.go | 2 +- forum_store.go | 14 +- gen_mssql.go | 462 +++++++++++++++++++++-------------------- gen_mysql.go | 462 +++++++++++++++++++++-------------------- gen_pgsql.go | 182 ++++++++-------- gen_router.go | 85 ++++++++ group.go | 2 +- group_store.go | 3 +- main.go | 28 ++- member_routes.go | 87 +++----- misc_test.go | 15 ++ mod_routes.go | 24 +-- mssql.go | 10 - mysql.go | 27 +-- panel_routes.go | 62 +++--- pgsql.go | 6 - query_gen/lib/mssql.go | 27 ++- query_gen/lib/mysql.go | 49 +++-- query_gen/lib/pgsql.go | 19 +- reply.go | 20 +- router_gen/main.go | 58 +++++- router_gen/routes.go | 130 +++++++----- routes.go | 16 +- routes_common.go | 12 +- setting.go | 2 +- tasks.go | 4 +- themes.go | 2 +- topic.go | 20 +- topic_store.go | 4 +- user.go | 38 ++-- utils.go | 6 +- widgets.go | 3 +- word_filters.go | 2 +- 38 files changed, 1065 insertions(+), 833 deletions(-) diff --git a/alerts.go b/alerts.go index bc36461c..2b3d596c 100644 --- a/alerts.go +++ b/alerts.go @@ -122,7 +122,7 @@ func buildAlert(asid int, event string, elementType string, actorID int, targetU } func notifyWatchers(asid int64) { - rows, err := getWatchersStmt.Query(asid) + rows, err := stmts.getWatchers.Query(asid) if err != nil && err != ErrNoRows { log.Fatal(err.Error()) return @@ -147,7 +147,7 @@ func notifyWatchers(asid int64) { var actorID, targetUserID, elementID int var event, elementType string - err = getActivityEntryStmt.QueryRow(asid).Scan(&actorID, &targetUserID, &event, &elementType, &elementID) + err = stmts.getActivityEntry.QueryRow(asid).Scan(&actorID, &targetUserID, &event, &elementType, &elementID) if err != nil && err != ErrNoRows { log.Fatal(err.Error()) return diff --git a/auth.go b/auth.go index fced9676..306a6591 100644 --- a/auth.go +++ b/auth.go @@ -170,7 +170,7 @@ func (auth *DefaultAuth) CreateSession(uid int) (session string, err error) { return "", err } - _, err = updateSessionStmt.Exec(session, uid) + _, err = stmts.updateSession.Exec(session, uid) if err != nil { return "", err } diff --git a/database.go b/database.go index 6b65af9d..27b9ff3b 100644 --- a/database.go +++ b/database.go @@ -4,6 +4,8 @@ import "log" import "database/sql" +var stmts *Stmts + var db *sql.DB var dbVersion string var dbAdapter string @@ -14,11 +16,14 @@ var ErrNoRows = sql.ErrNoRows var _initDatabase func() error func initDatabase() (err error) { + stmts = &Stmts{Mocks: false} + // Engine specific code err = _initDatabase() if err != nil { return err } + globs = &Globs{stmts} log.Print("Loading the usergroups.") gstore, err = NewMemoryGroupStore() diff --git a/extend.go b/extend.go index e55a1b37..269b44f7 100644 --- a/extend.go +++ b/extend.go @@ -143,7 +143,7 @@ func initExtend() (err error) { // LoadPlugins polls the database to see which plugins have been activated and which have been installed func LoadPlugins() error { - rows, err := getPluginsStmt.Query() + rows, err := stmts.getPlugins.Query() if err != nil { return err } diff --git a/forum.go b/forum.go index 736124a2..023365f5 100644 --- a/forum.go +++ b/forum.go @@ -82,7 +82,7 @@ func (forum *Forum) Update(name string, desc string, active bool, preset string) name = forum.Name } preset = strings.TrimSpace(preset) - _, err := updateForumStmt.Exec(name, desc, active, preset, forum.ID) + _, err := stmts.updateForum.Exec(name, desc, active, preset, forum.ID) if err != nil { return err } diff --git a/forum_perms_store.go b/forum_perms_store.go index 62879008..6098a541 100644 --- a/forum_perms_store.go +++ b/forum_perms_store.go @@ -23,7 +23,7 @@ func (fps *ForumPermsStore) Init() error { log.Print("fids: ", fids) } - rows, err := getForumsPermissionsStmt.Query() + rows, err := stmts.getForumsPermissions.Query() if err != nil { return err } diff --git a/forum_store.go b/forum_store.go index f718571d..28577ff5 100644 --- a/forum_store.go +++ b/forum_store.go @@ -102,7 +102,8 @@ func (mfs *MemoryForumStore) LoadForums() error { } } - rows, err := getForumsStmt.Query() + // TODO: Move this statement into the store + rows, err := stmts.getForums.Query() if err != nil { return err } @@ -327,11 +328,11 @@ func (mfs *MemoryForumStore) Delete(id int) error { } func (mfs *MemoryForumStore) AddTopic(tid int, uid int, fid int) error { - _, err := updateForumCacheStmt.Exec(tid, uid, fid) + _, err := stmts.updateForumCache.Exec(tid, uid, fid) if err != nil { return err } - _, err = addTopicsToForumStmt.Exec(1, fid) + _, err = stmts.addTopicsToForum.Exec(1, fid) if err != nil { return err } @@ -341,7 +342,7 @@ func (mfs *MemoryForumStore) AddTopic(tid int, uid int, fid int) error { // TODO: Update the forum cache with the latest topic func (mfs *MemoryForumStore) RemoveTopic(fid int) error { - _, err := removeTopicsFromForumStmt.Exec(1, fid) + _, err := stmts.removeTopicsFromForum.Exec(1, fid) if err != nil { return err } @@ -353,7 +354,7 @@ func (mfs *MemoryForumStore) RemoveTopic(fid int) error { // DEPRECATED. forum.Update() will be the way to do this in the future, once it's completed // TODO: Have a pointer to the last topic rather than storing it on the forum itself func (mfs *MemoryForumStore) UpdateLastTopic(tid int, uid int, fid int) error { - _, err := updateForumCacheStmt.Exec(tid, uid, fid) + _, err := stmts.updateForumCache.Exec(tid, uid, fid) if err != nil { return err } @@ -363,7 +364,8 @@ func (mfs *MemoryForumStore) UpdateLastTopic(tid int, uid int, fid int) error { func (mfs *MemoryForumStore) Create(forumName string, forumDesc string, active bool, preset string) (int, error) { forumCreateMutex.Lock() - res, err := createForumStmt.Exec(forumName, forumDesc, active, preset) + // TODO: Move this query into the store + res, err := stmts.createForum.Exec(forumName, forumDesc, active, preset) if err != nil { return 0, err } diff --git a/gen_mssql.go b/gen_mssql.go index b658d404..c3b15682 100644 --- a/gen_mssql.go +++ b/gen_mssql.go @@ -7,118 +7,132 @@ import "log" import "database/sql" // nolint -var getReplyStmt *sql.Stmt -var getUserReplyStmt *sql.Stmt -var getPasswordStmt *sql.Stmt -var getSettingsStmt *sql.Stmt -var getSettingStmt *sql.Stmt -var getFullSettingStmt *sql.Stmt -var getFullSettingsStmt *sql.Stmt -var getGroupsStmt *sql.Stmt -var getForumsStmt *sql.Stmt -var getForumsPermissionsStmt *sql.Stmt -var getPluginsStmt *sql.Stmt -var getThemesStmt *sql.Stmt -var getWidgetsStmt *sql.Stmt -var isPluginActiveStmt *sql.Stmt -var getUsersOffsetStmt *sql.Stmt -var getWordFiltersStmt *sql.Stmt -var isThemeDefaultStmt *sql.Stmt -var getModlogsStmt *sql.Stmt -var getModlogsOffsetStmt *sql.Stmt -var getReplyTIDStmt *sql.Stmt -var getTopicFIDStmt *sql.Stmt -var getUserReplyUIDStmt *sql.Stmt -var hasLikedTopicStmt *sql.Stmt -var hasLikedReplyStmt *sql.Stmt -var getUserNameStmt *sql.Stmt -var getEmailsByUserStmt *sql.Stmt -var getTopicBasicStmt *sql.Stmt -var getActivityEntryStmt *sql.Stmt -var forumEntryExistsStmt *sql.Stmt -var groupEntryExistsStmt *sql.Stmt -var getForumTopicsOffsetStmt *sql.Stmt -var getExpiredScheduledGroupsStmt *sql.Stmt -var getSyncStmt *sql.Stmt -var getAttachmentStmt *sql.Stmt -var getTopicRepliesOffsetStmt *sql.Stmt -var getTopicListStmt *sql.Stmt -var getTopicUserStmt *sql.Stmt -var getTopicByReplyStmt *sql.Stmt -var getTopicRepliesStmt *sql.Stmt -var getForumTopicsStmt *sql.Stmt -var getProfileRepliesStmt *sql.Stmt -var getWatchersStmt *sql.Stmt -var createTopicStmt *sql.Stmt -var createReportStmt *sql.Stmt -var createReplyStmt *sql.Stmt -var createActionReplyStmt *sql.Stmt -var createLikeStmt *sql.Stmt -var addActivityStmt *sql.Stmt -var notifyOneStmt *sql.Stmt -var addEmailStmt *sql.Stmt -var createProfileReplyStmt *sql.Stmt -var addSubscriptionStmt *sql.Stmt -var createForumStmt *sql.Stmt -var addForumPermsToForumStmt *sql.Stmt -var addPluginStmt *sql.Stmt -var addThemeStmt *sql.Stmt -var addModlogEntryStmt *sql.Stmt -var addAdminlogEntryStmt *sql.Stmt -var addAttachmentStmt *sql.Stmt -var createWordFilterStmt *sql.Stmt -var addRepliesToTopicStmt *sql.Stmt -var removeRepliesFromTopicStmt *sql.Stmt -var addTopicsToForumStmt *sql.Stmt -var removeTopicsFromForumStmt *sql.Stmt -var updateForumCacheStmt *sql.Stmt -var addLikesToTopicStmt *sql.Stmt -var addLikesToReplyStmt *sql.Stmt -var editTopicStmt *sql.Stmt -var editReplyStmt *sql.Stmt -var stickTopicStmt *sql.Stmt -var unstickTopicStmt *sql.Stmt -var lockTopicStmt *sql.Stmt -var unlockTopicStmt *sql.Stmt -var updateLastIPStmt *sql.Stmt -var updateSessionStmt *sql.Stmt -var setPasswordStmt *sql.Stmt -var setAvatarStmt *sql.Stmt -var setUsernameStmt *sql.Stmt -var changeGroupStmt *sql.Stmt -var activateUserStmt *sql.Stmt -var updateUserLevelStmt *sql.Stmt -var incrementUserScoreStmt *sql.Stmt -var incrementUserPostsStmt *sql.Stmt -var incrementUserBigpostsStmt *sql.Stmt -var incrementUserMegapostsStmt *sql.Stmt -var incrementUserTopicsStmt *sql.Stmt -var editProfileReplyStmt *sql.Stmt -var updateForumStmt *sql.Stmt -var updateSettingStmt *sql.Stmt -var updatePluginStmt *sql.Stmt -var updatePluginInstallStmt *sql.Stmt -var updateThemeStmt *sql.Stmt -var updateUserStmt *sql.Stmt -var updateUserGroupStmt *sql.Stmt -var updateGroupPermsStmt *sql.Stmt -var updateGroupRankStmt *sql.Stmt -var updateGroupStmt *sql.Stmt -var updateEmailStmt *sql.Stmt -var verifyEmailStmt *sql.Stmt -var setTempGroupStmt *sql.Stmt -var updateWordFilterStmt *sql.Stmt -var bumpSyncStmt *sql.Stmt -var deleteUserStmt *sql.Stmt -var deleteTopicStmt *sql.Stmt -var deleteReplyStmt *sql.Stmt -var deleteProfileReplyStmt *sql.Stmt -var deleteActivityStreamMatchStmt *sql.Stmt -var deleteWordFilterStmt *sql.Stmt -var reportExistsStmt *sql.Stmt -var groupCountStmt *sql.Stmt -var modlogCountStmt *sql.Stmt -var notifyWatchersStmt *sql.Stmt +type Stmts struct { + getReply *sql.Stmt + getUserReply *sql.Stmt + getPassword *sql.Stmt + getSettings *sql.Stmt + getSetting *sql.Stmt + getFullSetting *sql.Stmt + getFullSettings *sql.Stmt + getGroups *sql.Stmt + getForums *sql.Stmt + getForumsPermissions *sql.Stmt + getPlugins *sql.Stmt + getThemes *sql.Stmt + getWidgets *sql.Stmt + isPluginActive *sql.Stmt + getUsersOffset *sql.Stmt + getWordFilters *sql.Stmt + isThemeDefault *sql.Stmt + getModlogs *sql.Stmt + getModlogsOffset *sql.Stmt + getReplyTID *sql.Stmt + getTopicFID *sql.Stmt + getUserReplyUID *sql.Stmt + hasLikedTopic *sql.Stmt + hasLikedReply *sql.Stmt + getUserName *sql.Stmt + getEmailsByUser *sql.Stmt + getTopicBasic *sql.Stmt + getActivityEntry *sql.Stmt + forumEntryExists *sql.Stmt + groupEntryExists *sql.Stmt + getForumTopicsOffset *sql.Stmt + getExpiredScheduledGroups *sql.Stmt + getSync *sql.Stmt + getAttachment *sql.Stmt + getTopicRepliesOffset *sql.Stmt + getTopicList *sql.Stmt + getTopicUser *sql.Stmt + getTopicByReply *sql.Stmt + getTopicReplies *sql.Stmt + getForumTopics *sql.Stmt + getProfileReplies *sql.Stmt + getWatchers *sql.Stmt + createTopic *sql.Stmt + createReport *sql.Stmt + createReply *sql.Stmt + createActionReply *sql.Stmt + createLike *sql.Stmt + addActivity *sql.Stmt + notifyOne *sql.Stmt + addEmail *sql.Stmt + createProfileReply *sql.Stmt + addSubscription *sql.Stmt + createForum *sql.Stmt + addForumPermsToForum *sql.Stmt + addPlugin *sql.Stmt + addTheme *sql.Stmt + addModlogEntry *sql.Stmt + addAdminlogEntry *sql.Stmt + addAttachment *sql.Stmt + createWordFilter *sql.Stmt + addRepliesToTopic *sql.Stmt + removeRepliesFromTopic *sql.Stmt + addTopicsToForum *sql.Stmt + removeTopicsFromForum *sql.Stmt + updateForumCache *sql.Stmt + addLikesToTopic *sql.Stmt + addLikesToReply *sql.Stmt + editTopic *sql.Stmt + editReply *sql.Stmt + stickTopic *sql.Stmt + unstickTopic *sql.Stmt + lockTopic *sql.Stmt + unlockTopic *sql.Stmt + updateLastIP *sql.Stmt + updateSession *sql.Stmt + setPassword *sql.Stmt + setAvatar *sql.Stmt + setUsername *sql.Stmt + changeGroup *sql.Stmt + activateUser *sql.Stmt + updateUserLevel *sql.Stmt + incrementUserScore *sql.Stmt + incrementUserPosts *sql.Stmt + incrementUserBigposts *sql.Stmt + incrementUserMegaposts *sql.Stmt + incrementUserTopics *sql.Stmt + editProfileReply *sql.Stmt + updateForum *sql.Stmt + updateSetting *sql.Stmt + updatePlugin *sql.Stmt + updatePluginInstall *sql.Stmt + updateTheme *sql.Stmt + updateUser *sql.Stmt + updateUserGroup *sql.Stmt + updateGroupPerms *sql.Stmt + updateGroupRank *sql.Stmt + updateGroup *sql.Stmt + updateEmail *sql.Stmt + verifyEmail *sql.Stmt + setTempGroup *sql.Stmt + updateWordFilter *sql.Stmt + bumpSync *sql.Stmt + deleteUser *sql.Stmt + deleteTopic *sql.Stmt + deleteReply *sql.Stmt + deleteProfileReply *sql.Stmt + deleteActivityStreamMatch *sql.Stmt + deleteWordFilter *sql.Stmt + reportExists *sql.Stmt + groupCount *sql.Stmt + modlogCount *sql.Stmt + notifyWatchers *sql.Stmt + + getActivityFeedByWatcher *sql.Stmt + getActivityCountByWatcher *sql.Stmt + todaysPostCount *sql.Stmt + todaysTopicCount *sql.Stmt + todaysReportCount *sql.Stmt + todaysNewUserCount *sql.Stmt + findUsersByIPUsers *sql.Stmt + findUsersByIPTopics *sql.Stmt + findUsersByIPReplies *sql.Stmt + + Mocks bool +} // nolint func _gen_mssql() (err error) { @@ -127,784 +141,784 @@ func _gen_mssql() (err error) { } log.Print("Preparing getReply statement.") - getReplyStmt, err = db.Prepare("SELECT [tid],[content],[createdBy],[createdAt],[lastEdit],[lastEditBy],[ipaddress],[likeCount] FROM [replies] WHERE [rid] = ?1") + stmts.getReply, err = db.Prepare("SELECT [tid],[content],[createdBy],[createdAt],[lastEdit],[lastEditBy],[ipaddress],[likeCount] FROM [replies] WHERE [rid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [tid],[content],[createdBy],[createdAt],[lastEdit],[lastEditBy],[ipaddress],[likeCount] FROM [replies] WHERE [rid] = ?1") return err } log.Print("Preparing getUserReply statement.") - getUserReplyStmt, err = db.Prepare("SELECT [uid],[content],[createdBy],[createdAt],[lastEdit],[lastEditBy],[ipaddress] FROM [users_replies] WHERE [rid] = ?1") + stmts.getUserReply, err = db.Prepare("SELECT [uid],[content],[createdBy],[createdAt],[lastEdit],[lastEditBy],[ipaddress] FROM [users_replies] WHERE [rid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [uid],[content],[createdBy],[createdAt],[lastEdit],[lastEditBy],[ipaddress] FROM [users_replies] WHERE [rid] = ?1") return err } log.Print("Preparing getPassword statement.") - getPasswordStmt, err = db.Prepare("SELECT [password],[salt] FROM [users] WHERE [uid] = ?1") + stmts.getPassword, err = db.Prepare("SELECT [password],[salt] FROM [users] WHERE [uid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [password],[salt] FROM [users] WHERE [uid] = ?1") return err } log.Print("Preparing getSettings statement.") - getSettingsStmt, err = db.Prepare("SELECT [name],[content],[type] FROM [settings]") + stmts.getSettings, err = db.Prepare("SELECT [name],[content],[type] FROM [settings]") if err != nil { log.Print("Bad Query: ","SELECT [name],[content],[type] FROM [settings]") return err } log.Print("Preparing getSetting statement.") - getSettingStmt, err = db.Prepare("SELECT [content],[type] FROM [settings] WHERE [name] = ?1") + stmts.getSetting, err = db.Prepare("SELECT [content],[type] FROM [settings] WHERE [name] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [content],[type] FROM [settings] WHERE [name] = ?1") return err } log.Print("Preparing getFullSetting statement.") - getFullSettingStmt, err = db.Prepare("SELECT [name],[type],[constraints] FROM [settings] WHERE [name] = ?1") + stmts.getFullSetting, err = db.Prepare("SELECT [name],[type],[constraints] FROM [settings] WHERE [name] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [name],[type],[constraints] FROM [settings] WHERE [name] = ?1") return err } log.Print("Preparing getFullSettings statement.") - getFullSettingsStmt, err = db.Prepare("SELECT [name],[content],[type],[constraints] FROM [settings]") + stmts.getFullSettings, err = db.Prepare("SELECT [name],[content],[type],[constraints] FROM [settings]") if err != nil { log.Print("Bad Query: ","SELECT [name],[content],[type],[constraints] FROM [settings]") return err } log.Print("Preparing getGroups statement.") - getGroupsStmt, err = db.Prepare("SELECT [gid],[name],[permissions],[plugin_perms],[is_mod],[is_admin],[is_banned],[tag] FROM [users_groups]") + stmts.getGroups, err = db.Prepare("SELECT [gid],[name],[permissions],[plugin_perms],[is_mod],[is_admin],[is_banned],[tag] FROM [users_groups]") if err != nil { log.Print("Bad Query: ","SELECT [gid],[name],[permissions],[plugin_perms],[is_mod],[is_admin],[is_banned],[tag] FROM [users_groups]") return err } log.Print("Preparing getForums statement.") - getForumsStmt, err = db.Prepare("SELECT [fid],[name],[desc],[active],[preset],[parentID],[parentType],[topicCount],[lastTopicID],[lastReplyerID] FROM [forums] ORDER BY fid ASC") + stmts.getForums, err = db.Prepare("SELECT [fid],[name],[desc],[active],[preset],[parentID],[parentType],[topicCount],[lastTopicID],[lastReplyerID] FROM [forums] ORDER BY fid ASC") if err != nil { log.Print("Bad Query: ","SELECT [fid],[name],[desc],[active],[preset],[parentID],[parentType],[topicCount],[lastTopicID],[lastReplyerID] FROM [forums] ORDER BY fid ASC") return err } log.Print("Preparing getForumsPermissions statement.") - getForumsPermissionsStmt, err = db.Prepare("SELECT [gid],[fid],[permissions] FROM [forums_permissions] ORDER BY gid ASC,fid ASC") + stmts.getForumsPermissions, err = db.Prepare("SELECT [gid],[fid],[permissions] FROM [forums_permissions] ORDER BY gid ASC,fid ASC") if err != nil { log.Print("Bad Query: ","SELECT [gid],[fid],[permissions] FROM [forums_permissions] ORDER BY gid ASC,fid ASC") return err } log.Print("Preparing getPlugins statement.") - getPluginsStmt, err = db.Prepare("SELECT [uname],[active],[installed] FROM [plugins]") + stmts.getPlugins, err = db.Prepare("SELECT [uname],[active],[installed] FROM [plugins]") if err != nil { log.Print("Bad Query: ","SELECT [uname],[active],[installed] FROM [plugins]") return err } log.Print("Preparing getThemes statement.") - getThemesStmt, err = db.Prepare("SELECT [uname],[default] FROM [themes]") + stmts.getThemes, err = db.Prepare("SELECT [uname],[default] FROM [themes]") if err != nil { log.Print("Bad Query: ","SELECT [uname],[default] FROM [themes]") return err } log.Print("Preparing getWidgets statement.") - getWidgetsStmt, err = db.Prepare("SELECT [position],[side],[type],[active],[location],[data] FROM [widgets] ORDER BY position ASC") + stmts.getWidgets, err = db.Prepare("SELECT [position],[side],[type],[active],[location],[data] FROM [widgets] ORDER BY position ASC") if err != nil { log.Print("Bad Query: ","SELECT [position],[side],[type],[active],[location],[data] FROM [widgets] ORDER BY position ASC") return err } log.Print("Preparing isPluginActive statement.") - isPluginActiveStmt, err = db.Prepare("SELECT [active] FROM [plugins] WHERE [uname] = ?1") + stmts.isPluginActive, err = db.Prepare("SELECT [active] FROM [plugins] WHERE [uname] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [active] FROM [plugins] WHERE [uname] = ?1") return err } log.Print("Preparing getUsersOffset statement.") - getUsersOffsetStmt, err = db.Prepare("SELECT [uid],[name],[group],[active],[is_super_admin],[avatar] FROM [users] ORDER BY uid ASC OFFSET ?1 ROWS FETCH NEXT ?2 ROWS ONLY") + stmts.getUsersOffset, err = db.Prepare("SELECT [uid],[name],[group],[active],[is_super_admin],[avatar] FROM [users] ORDER BY uid ASC OFFSET ?1 ROWS FETCH NEXT ?2 ROWS ONLY") if err != nil { log.Print("Bad Query: ","SELECT [uid],[name],[group],[active],[is_super_admin],[avatar] FROM [users] ORDER BY uid ASC OFFSET ?1 ROWS FETCH NEXT ?2 ROWS ONLY") return err } log.Print("Preparing getWordFilters statement.") - getWordFiltersStmt, err = db.Prepare("SELECT [wfid],[find],[replacement] FROM [word_filters]") + stmts.getWordFilters, err = db.Prepare("SELECT [wfid],[find],[replacement] FROM [word_filters]") if err != nil { log.Print("Bad Query: ","SELECT [wfid],[find],[replacement] FROM [word_filters]") return err } log.Print("Preparing isThemeDefault statement.") - isThemeDefaultStmt, err = db.Prepare("SELECT [default] FROM [themes] WHERE [uname] = ?1") + stmts.isThemeDefault, err = db.Prepare("SELECT [default] FROM [themes] WHERE [uname] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [default] FROM [themes] WHERE [uname] = ?1") return err } log.Print("Preparing getModlogs statement.") - getModlogsStmt, err = db.Prepare("SELECT [action],[elementID],[elementType],[ipaddress],[actorID],[doneAt] FROM [moderation_logs]") + stmts.getModlogs, err = db.Prepare("SELECT [action],[elementID],[elementType],[ipaddress],[actorID],[doneAt] FROM [moderation_logs]") if err != nil { log.Print("Bad Query: ","SELECT [action],[elementID],[elementType],[ipaddress],[actorID],[doneAt] FROM [moderation_logs]") return err } log.Print("Preparing getModlogsOffset statement.") - getModlogsOffsetStmt, err = db.Prepare("SELECT [action],[elementID],[elementType],[ipaddress],[actorID],[doneAt] FROM [moderation_logs] ORDER BY doneAt DESC OFFSET ?1 ROWS FETCH NEXT ?2 ROWS ONLY") + stmts.getModlogsOffset, err = db.Prepare("SELECT [action],[elementID],[elementType],[ipaddress],[actorID],[doneAt] FROM [moderation_logs] ORDER BY doneAt DESC OFFSET ?1 ROWS FETCH NEXT ?2 ROWS ONLY") if err != nil { log.Print("Bad Query: ","SELECT [action],[elementID],[elementType],[ipaddress],[actorID],[doneAt] FROM [moderation_logs] ORDER BY doneAt DESC OFFSET ?1 ROWS FETCH NEXT ?2 ROWS ONLY") return err } log.Print("Preparing getReplyTID statement.") - getReplyTIDStmt, err = db.Prepare("SELECT [tid] FROM [replies] WHERE [rid] = ?1") + stmts.getReplyTID, err = db.Prepare("SELECT [tid] FROM [replies] WHERE [rid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [tid] FROM [replies] WHERE [rid] = ?1") return err } log.Print("Preparing getTopicFID statement.") - getTopicFIDStmt, err = db.Prepare("SELECT [parentID] FROM [topics] WHERE [tid] = ?1") + stmts.getTopicFID, err = db.Prepare("SELECT [parentID] FROM [topics] WHERE [tid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [parentID] FROM [topics] WHERE [tid] = ?1") return err } log.Print("Preparing getUserReplyUID statement.") - getUserReplyUIDStmt, err = db.Prepare("SELECT [uid] FROM [users_replies] WHERE [rid] = ?1") + stmts.getUserReplyUID, err = db.Prepare("SELECT [uid] FROM [users_replies] WHERE [rid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [uid] FROM [users_replies] WHERE [rid] = ?1") return err } log.Print("Preparing hasLikedTopic statement.") - hasLikedTopicStmt, err = db.Prepare("SELECT [targetItem] FROM [likes] WHERE [sentBy] = ?1 AND [targetItem] = ?2 AND [targetType] = 'topics'") + stmts.hasLikedTopic, err = db.Prepare("SELECT [targetItem] FROM [likes] WHERE [sentBy] = ?1 AND [targetItem] = ?2 AND [targetType] = 'topics'") if err != nil { log.Print("Bad Query: ","SELECT [targetItem] FROM [likes] WHERE [sentBy] = ?1 AND [targetItem] = ?2 AND [targetType] = 'topics'") return err } log.Print("Preparing hasLikedReply statement.") - hasLikedReplyStmt, err = db.Prepare("SELECT [targetItem] FROM [likes] WHERE [sentBy] = ?1 AND [targetItem] = ?2 AND [targetType] = 'replies'") + stmts.hasLikedReply, err = db.Prepare("SELECT [targetItem] FROM [likes] WHERE [sentBy] = ?1 AND [targetItem] = ?2 AND [targetType] = 'replies'") if err != nil { log.Print("Bad Query: ","SELECT [targetItem] FROM [likes] WHERE [sentBy] = ?1 AND [targetItem] = ?2 AND [targetType] = 'replies'") return err } log.Print("Preparing getUserName statement.") - getUserNameStmt, err = db.Prepare("SELECT [name] FROM [users] WHERE [uid] = ?1") + stmts.getUserName, err = db.Prepare("SELECT [name] FROM [users] WHERE [uid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [name] FROM [users] WHERE [uid] = ?1") return err } log.Print("Preparing getEmailsByUser statement.") - getEmailsByUserStmt, err = db.Prepare("SELECT [email],[validated],[token] FROM [emails] WHERE [uid] = ?1") + stmts.getEmailsByUser, err = db.Prepare("SELECT [email],[validated],[token] FROM [emails] WHERE [uid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [email],[validated],[token] FROM [emails] WHERE [uid] = ?1") return err } log.Print("Preparing getTopicBasic statement.") - getTopicBasicStmt, err = db.Prepare("SELECT [title],[content] FROM [topics] WHERE [tid] = ?1") + stmts.getTopicBasic, err = db.Prepare("SELECT [title],[content] FROM [topics] WHERE [tid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [title],[content] FROM [topics] WHERE [tid] = ?1") return err } log.Print("Preparing getActivityEntry statement.") - getActivityEntryStmt, err = db.Prepare("SELECT [actor],[targetUser],[event],[elementType],[elementID] FROM [activity_stream] WHERE [asid] = ?1") + stmts.getActivityEntry, err = db.Prepare("SELECT [actor],[targetUser],[event],[elementType],[elementID] FROM [activity_stream] WHERE [asid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [actor],[targetUser],[event],[elementType],[elementID] FROM [activity_stream] WHERE [asid] = ?1") return err } log.Print("Preparing forumEntryExists statement.") - forumEntryExistsStmt, err = db.Prepare("SELECT [fid] FROM [forums] WHERE [name] = '' ORDER BY fid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY") + stmts.forumEntryExists, err = db.Prepare("SELECT [fid] FROM [forums] WHERE [name] = '' ORDER BY fid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY") if err != nil { log.Print("Bad Query: ","SELECT [fid] FROM [forums] WHERE [name] = '' ORDER BY fid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY") return err } log.Print("Preparing groupEntryExists statement.") - groupEntryExistsStmt, err = db.Prepare("SELECT [gid] FROM [users_groups] WHERE [name] = '' ORDER BY gid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY") + stmts.groupEntryExists, err = db.Prepare("SELECT [gid] FROM [users_groups] WHERE [name] = '' ORDER BY gid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY") if err != nil { log.Print("Bad Query: ","SELECT [gid] FROM [users_groups] WHERE [name] = '' ORDER BY gid ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY") return err } log.Print("Preparing getForumTopicsOffset statement.") - getForumTopicsOffsetStmt, err = db.Prepare("SELECT [tid],[title],[content],[createdBy],[is_closed],[sticky],[createdAt],[lastReplyAt],[lastReplyBy],[parentID],[postCount],[likeCount] FROM [topics] WHERE [parentID] = ?1 ORDER BY sticky DESC,lastReplyAt DESC,createdBy DESC OFFSET ?2 ROWS FETCH NEXT ?3 ROWS ONLY") + stmts.getForumTopicsOffset, err = db.Prepare("SELECT [tid],[title],[content],[createdBy],[is_closed],[sticky],[createdAt],[lastReplyAt],[lastReplyBy],[parentID],[postCount],[likeCount] FROM [topics] WHERE [parentID] = ?1 ORDER BY sticky DESC,lastReplyAt DESC,createdBy DESC OFFSET ?2 ROWS FETCH NEXT ?3 ROWS ONLY") if err != nil { log.Print("Bad Query: ","SELECT [tid],[title],[content],[createdBy],[is_closed],[sticky],[createdAt],[lastReplyAt],[lastReplyBy],[parentID],[postCount],[likeCount] FROM [topics] WHERE [parentID] = ?1 ORDER BY sticky DESC,lastReplyAt DESC,createdBy DESC OFFSET ?2 ROWS FETCH NEXT ?3 ROWS ONLY") return err } log.Print("Preparing getExpiredScheduledGroups statement.") - getExpiredScheduledGroupsStmt, err = db.Prepare("SELECT [uid] FROM [users_groups_scheduler] WHERE GETDATE() > [revert_at] AND [temporary] = 1") + stmts.getExpiredScheduledGroups, err = db.Prepare("SELECT [uid] FROM [users_groups_scheduler] WHERE GETDATE() > [revert_at] AND [temporary] = 1") if err != nil { log.Print("Bad Query: ","SELECT [uid] FROM [users_groups_scheduler] WHERE GETDATE() > [revert_at] AND [temporary] = 1") return err } log.Print("Preparing getSync statement.") - getSyncStmt, err = db.Prepare("SELECT [last_update] FROM [sync]") + stmts.getSync, err = db.Prepare("SELECT [last_update] FROM [sync]") if err != nil { log.Print("Bad Query: ","SELECT [last_update] FROM [sync]") return err } log.Print("Preparing getAttachment statement.") - getAttachmentStmt, err = db.Prepare("SELECT [sectionID],[sectionTable],[originID],[originTable],[uploadedBy],[path] FROM [attachments] WHERE [path] = ?1 AND [sectionID] = ?2 AND [sectionTable] = ?3") + stmts.getAttachment, err = db.Prepare("SELECT [sectionID],[sectionTable],[originID],[originTable],[uploadedBy],[path] FROM [attachments] WHERE [path] = ?1 AND [sectionID] = ?2 AND [sectionTable] = ?3") if err != nil { log.Print("Bad Query: ","SELECT [sectionID],[sectionTable],[originID],[originTable],[uploadedBy],[path] FROM [attachments] WHERE [path] = ?1 AND [sectionID] = ?2 AND [sectionTable] = ?3") return err } log.Print("Preparing getTopicRepliesOffset statement.") - getTopicRepliesOffsetStmt, err = db.Prepare("SELECT [replies].[rid],[replies].[content],[replies].[createdBy],[replies].[createdAt],[replies].[lastEdit],[replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level],[replies].[ipaddress],[replies].[likeCount],[replies].[actionType] FROM [replies] LEFT JOIN [users] ON [replies].[createdBy] = [users].[uid] WHERE [replies].[tid] = ?1 ORDER BY replies.rid ASC OFFSET ?2 ROWS FETCH NEXT ?3 ROWS ONLY") + stmts.getTopicRepliesOffset, err = db.Prepare("SELECT [replies].[rid],[replies].[content],[replies].[createdBy],[replies].[createdAt],[replies].[lastEdit],[replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level],[replies].[ipaddress],[replies].[likeCount],[replies].[actionType] FROM [replies] LEFT JOIN [users] ON [replies].[createdBy] = [users].[uid] WHERE [replies].[tid] = ?1 ORDER BY replies.rid ASC OFFSET ?2 ROWS FETCH NEXT ?3 ROWS ONLY") if err != nil { log.Print("Bad Query: ","SELECT [replies].[rid],[replies].[content],[replies].[createdBy],[replies].[createdAt],[replies].[lastEdit],[replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level],[replies].[ipaddress],[replies].[likeCount],[replies].[actionType] FROM [replies] LEFT JOIN [users] ON [replies].[createdBy] = [users].[uid] WHERE [replies].[tid] = ?1 ORDER BY replies.rid ASC OFFSET ?2 ROWS FETCH NEXT ?3 ROWS ONLY") return err } log.Print("Preparing getTopicList statement.") - getTopicListStmt, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") + stmts.getTopicList, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") if err != nil { log.Print("Bad Query: ","SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") return err } log.Print("Preparing getTopicUser statement.") - getTopicUserStmt, err = db.Prepare("SELECT [topics].[title],[topics].[content],[topics].[createdBy],[topics].[createdAt],[topics].[is_closed],[topics].[sticky],[topics].[parentID],[topics].[ipaddress],[topics].[postCount],[topics].[likeCount],[users].[name],[users].[avatar],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] WHERE [tid] = ?1") + stmts.getTopicUser, err = db.Prepare("SELECT [topics].[title],[topics].[content],[topics].[createdBy],[topics].[createdAt],[topics].[is_closed],[topics].[sticky],[topics].[parentID],[topics].[ipaddress],[topics].[postCount],[topics].[likeCount],[users].[name],[users].[avatar],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] WHERE [tid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [topics].[title],[topics].[content],[topics].[createdBy],[topics].[createdAt],[topics].[is_closed],[topics].[sticky],[topics].[parentID],[topics].[ipaddress],[topics].[postCount],[topics].[likeCount],[users].[name],[users].[avatar],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] WHERE [tid] = ?1") return err } log.Print("Preparing getTopicByReply statement.") - getTopicByReplyStmt, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[createdAt],[topics].[is_closed],[topics].[sticky],[topics].[parentID],[topics].[ipaddress],[topics].[postCount],[topics].[likeCount],[topics].[data] FROM [replies] LEFT JOIN [topics] ON [replies].[tid] = [topics].[tid] WHERE [rid] = ?1") + stmts.getTopicByReply, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[createdAt],[topics].[is_closed],[topics].[sticky],[topics].[parentID],[topics].[ipaddress],[topics].[postCount],[topics].[likeCount],[topics].[data] FROM [replies] LEFT JOIN [topics] ON [replies].[tid] = [topics].[tid] WHERE [rid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[createdAt],[topics].[is_closed],[topics].[sticky],[topics].[parentID],[topics].[ipaddress],[topics].[postCount],[topics].[likeCount],[topics].[data] FROM [replies] LEFT JOIN [topics] ON [replies].[tid] = [topics].[tid] WHERE [rid] = ?1") return err } log.Print("Preparing getTopicReplies statement.") - getTopicRepliesStmt, err = db.Prepare("SELECT [replies].[rid],[replies].[content],[replies].[createdBy],[replies].[createdAt],[replies].[lastEdit],[replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level],[replies].[ipaddress] FROM [replies] LEFT JOIN [users] ON [replies].[createdBy] = [users].[uid] WHERE [tid] = ?1") + stmts.getTopicReplies, err = db.Prepare("SELECT [replies].[rid],[replies].[content],[replies].[createdBy],[replies].[createdAt],[replies].[lastEdit],[replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level],[replies].[ipaddress] FROM [replies] LEFT JOIN [users] ON [replies].[createdBy] = [users].[uid] WHERE [tid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [replies].[rid],[replies].[content],[replies].[createdBy],[replies].[createdAt],[replies].[lastEdit],[replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group],[users].[url_prefix],[users].[url_name],[users].[level],[replies].[ipaddress] FROM [replies] LEFT JOIN [users] ON [replies].[createdBy] = [users].[uid] WHERE [tid] = ?1") return err } log.Print("Preparing getForumTopics statement.") - getForumTopicsStmt, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[lastReplyAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] WHERE [topics].[parentID] = ?1 ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") + stmts.getForumTopics, err = db.Prepare("SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[lastReplyAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] WHERE [topics].[parentID] = ?1 ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") if err != nil { log.Print("Bad Query: ","SELECT [topics].[tid],[topics].[title],[topics].[content],[topics].[createdBy],[topics].[is_closed],[topics].[sticky],[topics].[createdAt],[topics].[lastReplyAt],[topics].[parentID],[users].[name],[users].[avatar] FROM [topics] LEFT JOIN [users] ON [topics].[createdBy] = [users].[uid] WHERE [topics].[parentID] = ?1 ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") return err } log.Print("Preparing getProfileReplies statement.") - getProfileRepliesStmt, err = db.Prepare("SELECT [users_replies].[rid],[users_replies].[content],[users_replies].[createdBy],[users_replies].[createdAt],[users_replies].[lastEdit],[users_replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group] FROM [users_replies] LEFT JOIN [users] ON [users_replies].[createdBy] = [users].[uid] WHERE [users_replies].[uid] = ?1") + stmts.getProfileReplies, err = db.Prepare("SELECT [users_replies].[rid],[users_replies].[content],[users_replies].[createdBy],[users_replies].[createdAt],[users_replies].[lastEdit],[users_replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group] FROM [users_replies] LEFT JOIN [users] ON [users_replies].[createdBy] = [users].[uid] WHERE [users_replies].[uid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [users_replies].[rid],[users_replies].[content],[users_replies].[createdBy],[users_replies].[createdAt],[users_replies].[lastEdit],[users_replies].[lastEditBy],[users].[avatar],[users].[name],[users].[group] FROM [users_replies] LEFT JOIN [users] ON [users_replies].[createdBy] = [users].[uid] WHERE [users_replies].[uid] = ?1") return err } log.Print("Preparing getWatchers statement.") - getWatchersStmt, err = db.Prepare("SELECT [activity_subscriptions].[user] FROM [activity_stream] INNER JOIN [activity_subscriptions] ON [activity_subscriptions].[targetType] = [activity_stream].[elementType] AND [activity_subscriptions].[targetID] = [activity_stream].[elementID] AND [activity_subscriptions].[user] != [activity_stream].[actor] WHERE [asid] = ?1") + stmts.getWatchers, err = db.Prepare("SELECT [activity_subscriptions].[user] FROM [activity_stream] INNER JOIN [activity_subscriptions] ON [activity_subscriptions].[targetType] = [activity_stream].[elementType] AND [activity_subscriptions].[targetID] = [activity_stream].[elementID] AND [activity_subscriptions].[user] != [activity_stream].[actor] WHERE [asid] = ?1") if err != nil { log.Print("Bad Query: ","SELECT [activity_subscriptions].[user] FROM [activity_stream] INNER JOIN [activity_subscriptions] ON [activity_subscriptions].[targetType] = [activity_stream].[elementType] AND [activity_subscriptions].[targetID] = [activity_stream].[elementID] AND [activity_subscriptions].[user] != [activity_stream].[actor] WHERE [asid] = ?1") return err } log.Print("Preparing createTopic statement.") - createTopicStmt, err = db.Prepare("INSERT INTO [topics] ([parentID],[title],[content],[parsed_content],[createdAt],[lastReplyAt],[lastReplyBy],[ipaddress],[words],[createdBy]) VALUES (?,?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?,?)") + stmts.createTopic, err = db.Prepare("INSERT INTO [topics] ([parentID],[title],[content],[parsed_content],[createdAt],[lastReplyAt],[lastReplyBy],[ipaddress],[words],[createdBy]) VALUES (?,?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [topics] ([parentID],[title],[content],[parsed_content],[createdAt],[lastReplyAt],[lastReplyBy],[ipaddress],[words],[createdBy]) VALUES (?,?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?,?)") return err } log.Print("Preparing createReport statement.") - createReportStmt, err = db.Prepare("INSERT INTO [topics] ([title],[content],[parsed_content],[createdAt],[lastReplyAt],[createdBy],[lastReplyBy],[data],[parentID],[css_class]) VALUES (?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?,1,'report')") + stmts.createReport, err = db.Prepare("INSERT INTO [topics] ([title],[content],[parsed_content],[createdAt],[lastReplyAt],[createdBy],[lastReplyBy],[data],[parentID],[css_class]) VALUES (?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?,1,'report')") if err != nil { log.Print("Bad Query: ","INSERT INTO [topics] ([title],[content],[parsed_content],[createdAt],[lastReplyAt],[createdBy],[lastReplyBy],[data],[parentID],[css_class]) VALUES (?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?,1,'report')") return err } log.Print("Preparing createReply statement.") - createReplyStmt, err = db.Prepare("INSERT INTO [replies] ([tid],[content],[parsed_content],[createdAt],[lastUpdated],[ipaddress],[words],[createdBy]) VALUES (?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?)") + stmts.createReply, err = db.Prepare("INSERT INTO [replies] ([tid],[content],[parsed_content],[createdAt],[lastUpdated],[ipaddress],[words],[createdBy]) VALUES (?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [replies] ([tid],[content],[parsed_content],[createdAt],[lastUpdated],[ipaddress],[words],[createdBy]) VALUES (?,?,?,GETUTCDATE(),GETUTCDATE(),?,?,?)") return err } log.Print("Preparing createActionReply statement.") - createActionReplyStmt, err = db.Prepare("INSERT INTO [replies] ([tid],[actionType],[ipaddress],[createdBy],[createdAt],[lastUpdated],[content],[parsed_content]) VALUES (?,?,?,?,GETUTCDATE(),GETUTCDATE(),'','')") + stmts.createActionReply, err = db.Prepare("INSERT INTO [replies] ([tid],[actionType],[ipaddress],[createdBy],[createdAt],[lastUpdated],[content],[parsed_content]) VALUES (?,?,?,?,GETUTCDATE(),GETUTCDATE(),'','')") if err != nil { log.Print("Bad Query: ","INSERT INTO [replies] ([tid],[actionType],[ipaddress],[createdBy],[createdAt],[lastUpdated],[content],[parsed_content]) VALUES (?,?,?,?,GETUTCDATE(),GETUTCDATE(),'','')") return err } log.Print("Preparing createLike statement.") - createLikeStmt, err = db.Prepare("INSERT INTO [likes] ([weight],[targetItem],[targetType],[sentBy]) VALUES (?,?,?,?)") + stmts.createLike, err = db.Prepare("INSERT INTO [likes] ([weight],[targetItem],[targetType],[sentBy]) VALUES (?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [likes] ([weight],[targetItem],[targetType],[sentBy]) VALUES (?,?,?,?)") return err } log.Print("Preparing addActivity statement.") - addActivityStmt, err = db.Prepare("INSERT INTO [activity_stream] ([actor],[targetUser],[event],[elementType],[elementID]) VALUES (?,?,?,?,?)") + stmts.addActivity, err = db.Prepare("INSERT INTO [activity_stream] ([actor],[targetUser],[event],[elementType],[elementID]) VALUES (?,?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [activity_stream] ([actor],[targetUser],[event],[elementType],[elementID]) VALUES (?,?,?,?,?)") return err } log.Print("Preparing notifyOne statement.") - notifyOneStmt, err = db.Prepare("INSERT INTO [activity_stream_matches] ([watcher],[asid]) VALUES (?,?)") + stmts.notifyOne, err = db.Prepare("INSERT INTO [activity_stream_matches] ([watcher],[asid]) VALUES (?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [activity_stream_matches] ([watcher],[asid]) VALUES (?,?)") return err } log.Print("Preparing addEmail statement.") - addEmailStmt, err = db.Prepare("INSERT INTO [emails] ([email],[uid],[validated],[token]) VALUES (?,?,?,?)") + stmts.addEmail, err = db.Prepare("INSERT INTO [emails] ([email],[uid],[validated],[token]) VALUES (?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [emails] ([email],[uid],[validated],[token]) VALUES (?,?,?,?)") return err } log.Print("Preparing createProfileReply statement.") - createProfileReplyStmt, err = db.Prepare("INSERT INTO [users_replies] ([uid],[content],[parsed_content],[createdAt],[createdBy],[ipaddress]) VALUES (?,?,?,GETUTCDATE(),?,?)") + stmts.createProfileReply, err = db.Prepare("INSERT INTO [users_replies] ([uid],[content],[parsed_content],[createdAt],[createdBy],[ipaddress]) VALUES (?,?,?,GETUTCDATE(),?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [users_replies] ([uid],[content],[parsed_content],[createdAt],[createdBy],[ipaddress]) VALUES (?,?,?,GETUTCDATE(),?,?)") return err } log.Print("Preparing addSubscription statement.") - addSubscriptionStmt, err = db.Prepare("INSERT INTO [activity_subscriptions] ([user],[targetID],[targetType],[level]) VALUES (?,?,?,2)") + stmts.addSubscription, err = db.Prepare("INSERT INTO [activity_subscriptions] ([user],[targetID],[targetType],[level]) VALUES (?,?,?,2)") if err != nil { log.Print("Bad Query: ","INSERT INTO [activity_subscriptions] ([user],[targetID],[targetType],[level]) VALUES (?,?,?,2)") return err } log.Print("Preparing createForum statement.") - createForumStmt, err = db.Prepare("INSERT INTO [forums] ([name],[desc],[active],[preset]) VALUES (?,?,?,?)") + stmts.createForum, err = db.Prepare("INSERT INTO [forums] ([name],[desc],[active],[preset]) VALUES (?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [forums] ([name],[desc],[active],[preset]) VALUES (?,?,?,?)") return err } log.Print("Preparing addForumPermsToForum statement.") - addForumPermsToForumStmt, err = db.Prepare("INSERT INTO [forums_permissions] ([gid],[fid],[preset],[permissions]) VALUES (?,?,?,?)") + stmts.addForumPermsToForum, err = db.Prepare("INSERT INTO [forums_permissions] ([gid],[fid],[preset],[permissions]) VALUES (?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [forums_permissions] ([gid],[fid],[preset],[permissions]) VALUES (?,?,?,?)") return err } log.Print("Preparing addPlugin statement.") - addPluginStmt, err = db.Prepare("INSERT INTO [plugins] ([uname],[active],[installed]) VALUES (?,?,?)") + stmts.addPlugin, err = db.Prepare("INSERT INTO [plugins] ([uname],[active],[installed]) VALUES (?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [plugins] ([uname],[active],[installed]) VALUES (?,?,?)") return err } log.Print("Preparing addTheme statement.") - addThemeStmt, err = db.Prepare("INSERT INTO [themes] ([uname],[default]) VALUES (?,?)") + stmts.addTheme, err = db.Prepare("INSERT INTO [themes] ([uname],[default]) VALUES (?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [themes] ([uname],[default]) VALUES (?,?)") return err } log.Print("Preparing addModlogEntry statement.") - addModlogEntryStmt, err = db.Prepare("INSERT INTO [moderation_logs] ([action],[elementID],[elementType],[ipaddress],[actorID],[doneAt]) VALUES (?,?,?,?,?,GETUTCDATE())") + stmts.addModlogEntry, err = db.Prepare("INSERT INTO [moderation_logs] ([action],[elementID],[elementType],[ipaddress],[actorID],[doneAt]) VALUES (?,?,?,?,?,GETUTCDATE())") if err != nil { log.Print("Bad Query: ","INSERT INTO [moderation_logs] ([action],[elementID],[elementType],[ipaddress],[actorID],[doneAt]) VALUES (?,?,?,?,?,GETUTCDATE())") return err } log.Print("Preparing addAdminlogEntry statement.") - addAdminlogEntryStmt, err = db.Prepare("INSERT INTO [administration_logs] ([action],[elementID],[elementType],[ipaddress],[actorID],[doneAt]) VALUES (?,?,?,?,?,GETUTCDATE())") + stmts.addAdminlogEntry, err = db.Prepare("INSERT INTO [administration_logs] ([action],[elementID],[elementType],[ipaddress],[actorID],[doneAt]) VALUES (?,?,?,?,?,GETUTCDATE())") if err != nil { log.Print("Bad Query: ","INSERT INTO [administration_logs] ([action],[elementID],[elementType],[ipaddress],[actorID],[doneAt]) VALUES (?,?,?,?,?,GETUTCDATE())") return err } log.Print("Preparing addAttachment statement.") - addAttachmentStmt, err = db.Prepare("INSERT INTO [attachments] ([sectionID],[sectionTable],[originID],[originTable],[uploadedBy],[path]) VALUES (?,?,?,?,?,?)") + stmts.addAttachment, err = db.Prepare("INSERT INTO [attachments] ([sectionID],[sectionTable],[originID],[originTable],[uploadedBy],[path]) VALUES (?,?,?,?,?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [attachments] ([sectionID],[sectionTable],[originID],[originTable],[uploadedBy],[path]) VALUES (?,?,?,?,?,?)") return err } log.Print("Preparing createWordFilter statement.") - createWordFilterStmt, err = db.Prepare("INSERT INTO [word_filters] ([find],[replacement]) VALUES (?,?)") + stmts.createWordFilter, err = db.Prepare("INSERT INTO [word_filters] ([find],[replacement]) VALUES (?,?)") if err != nil { log.Print("Bad Query: ","INSERT INTO [word_filters] ([find],[replacement]) VALUES (?,?)") return err } log.Print("Preparing addRepliesToTopic statement.") - addRepliesToTopicStmt, err = db.Prepare("UPDATE [topics] SET [postCount] = [postCount] + ?,[lastReplyBy] = ?,[lastReplyAt] = GETUTCDATE() WHERE [tid] = ?") + stmts.addRepliesToTopic, err = db.Prepare("UPDATE [topics] SET [postCount] = [postCount] + ?,[lastReplyBy] = ?,[lastReplyAt] = GETUTCDATE() WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [postCount] = [postCount] + ?,[lastReplyBy] = ?,[lastReplyAt] = GETUTCDATE() WHERE [tid] = ?") return err } log.Print("Preparing removeRepliesFromTopic statement.") - removeRepliesFromTopicStmt, err = db.Prepare("UPDATE [topics] SET [postCount] = [postCount] - ? WHERE [tid] = ?") + stmts.removeRepliesFromTopic, err = db.Prepare("UPDATE [topics] SET [postCount] = [postCount] - ? WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [postCount] = [postCount] - ? WHERE [tid] = ?") return err } log.Print("Preparing addTopicsToForum statement.") - addTopicsToForumStmt, err = db.Prepare("UPDATE [forums] SET [topicCount] = [topicCount] + ? WHERE [fid] = ?") + stmts.addTopicsToForum, err = db.Prepare("UPDATE [forums] SET [topicCount] = [topicCount] + ? WHERE [fid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [forums] SET [topicCount] = [topicCount] + ? WHERE [fid] = ?") return err } log.Print("Preparing removeTopicsFromForum statement.") - removeTopicsFromForumStmt, err = db.Prepare("UPDATE [forums] SET [topicCount] = [topicCount] - ? WHERE [fid] = ?") + stmts.removeTopicsFromForum, err = db.Prepare("UPDATE [forums] SET [topicCount] = [topicCount] - ? WHERE [fid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [forums] SET [topicCount] = [topicCount] - ? WHERE [fid] = ?") return err } log.Print("Preparing updateForumCache statement.") - updateForumCacheStmt, err = db.Prepare("UPDATE [forums] SET [lastTopicID] = ?,[lastReplyerID] = ? WHERE [fid] = ?") + stmts.updateForumCache, err = db.Prepare("UPDATE [forums] SET [lastTopicID] = ?,[lastReplyerID] = ? WHERE [fid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [forums] SET [lastTopicID] = ?,[lastReplyerID] = ? WHERE [fid] = ?") return err } log.Print("Preparing addLikesToTopic statement.") - addLikesToTopicStmt, err = db.Prepare("UPDATE [topics] SET [likeCount] = [likeCount] + ? WHERE [tid] = ?") + stmts.addLikesToTopic, err = db.Prepare("UPDATE [topics] SET [likeCount] = [likeCount] + ? WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [likeCount] = [likeCount] + ? WHERE [tid] = ?") return err } log.Print("Preparing addLikesToReply statement.") - addLikesToReplyStmt, err = db.Prepare("UPDATE [replies] SET [likeCount] = [likeCount] + ? WHERE [rid] = ?") + stmts.addLikesToReply, err = db.Prepare("UPDATE [replies] SET [likeCount] = [likeCount] + ? WHERE [rid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [replies] SET [likeCount] = [likeCount] + ? WHERE [rid] = ?") return err } log.Print("Preparing editTopic statement.") - editTopicStmt, err = db.Prepare("UPDATE [topics] SET [title] = ?,[content] = ?,[parsed_content] = ? WHERE [tid] = ?") + stmts.editTopic, err = db.Prepare("UPDATE [topics] SET [title] = ?,[content] = ?,[parsed_content] = ? WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [title] = ?,[content] = ?,[parsed_content] = ? WHERE [tid] = ?") return err } log.Print("Preparing editReply statement.") - editReplyStmt, err = db.Prepare("UPDATE [replies] SET [content] = ?,[parsed_content] = ? WHERE [rid] = ?") + stmts.editReply, err = db.Prepare("UPDATE [replies] SET [content] = ?,[parsed_content] = ? WHERE [rid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [replies] SET [content] = ?,[parsed_content] = ? WHERE [rid] = ?") return err } log.Print("Preparing stickTopic statement.") - stickTopicStmt, err = db.Prepare("UPDATE [topics] SET [sticky] = 1 WHERE [tid] = ?") + stmts.stickTopic, err = db.Prepare("UPDATE [topics] SET [sticky] = 1 WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [sticky] = 1 WHERE [tid] = ?") return err } log.Print("Preparing unstickTopic statement.") - unstickTopicStmt, err = db.Prepare("UPDATE [topics] SET [sticky] = 0 WHERE [tid] = ?") + stmts.unstickTopic, err = db.Prepare("UPDATE [topics] SET [sticky] = 0 WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [sticky] = 0 WHERE [tid] = ?") return err } log.Print("Preparing lockTopic statement.") - lockTopicStmt, err = db.Prepare("UPDATE [topics] SET [is_closed] = 1 WHERE [tid] = ?") + stmts.lockTopic, err = db.Prepare("UPDATE [topics] SET [is_closed] = 1 WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [is_closed] = 1 WHERE [tid] = ?") return err } log.Print("Preparing unlockTopic statement.") - unlockTopicStmt, err = db.Prepare("UPDATE [topics] SET [is_closed] = 0 WHERE [tid] = ?") + stmts.unlockTopic, err = db.Prepare("UPDATE [topics] SET [is_closed] = 0 WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [topics] SET [is_closed] = 0 WHERE [tid] = ?") return err } log.Print("Preparing updateLastIP statement.") - updateLastIPStmt, err = db.Prepare("UPDATE [users] SET [last_ip] = ? WHERE [uid] = ?") + stmts.updateLastIP, err = db.Prepare("UPDATE [users] SET [last_ip] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [last_ip] = ? WHERE [uid] = ?") return err } log.Print("Preparing updateSession statement.") - updateSessionStmt, err = db.Prepare("UPDATE [users] SET [session] = ? WHERE [uid] = ?") + stmts.updateSession, err = db.Prepare("UPDATE [users] SET [session] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [session] = ? WHERE [uid] = ?") return err } log.Print("Preparing setPassword statement.") - setPasswordStmt, err = db.Prepare("UPDATE [users] SET [password] = ?,[salt] = ? WHERE [uid] = ?") + stmts.setPassword, err = db.Prepare("UPDATE [users] SET [password] = ?,[salt] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [password] = ?,[salt] = ? WHERE [uid] = ?") return err } log.Print("Preparing setAvatar statement.") - setAvatarStmt, err = db.Prepare("UPDATE [users] SET [avatar] = ? WHERE [uid] = ?") + stmts.setAvatar, err = db.Prepare("UPDATE [users] SET [avatar] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [avatar] = ? WHERE [uid] = ?") return err } log.Print("Preparing setUsername statement.") - setUsernameStmt, err = db.Prepare("UPDATE [users] SET [name] = ? WHERE [uid] = ?") + stmts.setUsername, err = db.Prepare("UPDATE [users] SET [name] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [name] = ? WHERE [uid] = ?") return err } log.Print("Preparing changeGroup statement.") - changeGroupStmt, err = db.Prepare("UPDATE [users] SET [group] = ? WHERE [uid] = ?") + stmts.changeGroup, err = db.Prepare("UPDATE [users] SET [group] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [group] = ? WHERE [uid] = ?") return err } log.Print("Preparing activateUser statement.") - activateUserStmt, err = db.Prepare("UPDATE [users] SET [active] = 1 WHERE [uid] = ?") + stmts.activateUser, err = db.Prepare("UPDATE [users] SET [active] = 1 WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [active] = 1 WHERE [uid] = ?") return err } log.Print("Preparing updateUserLevel statement.") - updateUserLevelStmt, err = db.Prepare("UPDATE [users] SET [level] = ? WHERE [uid] = ?") + stmts.updateUserLevel, err = db.Prepare("UPDATE [users] SET [level] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [level] = ? WHERE [uid] = ?") return err } log.Print("Preparing incrementUserScore statement.") - incrementUserScoreStmt, err = db.Prepare("UPDATE [users] SET [score] = [score] + ? WHERE [uid] = ?") + stmts.incrementUserScore, err = db.Prepare("UPDATE [users] SET [score] = [score] + ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [score] = [score] + ? WHERE [uid] = ?") return err } log.Print("Preparing incrementUserPosts statement.") - incrementUserPostsStmt, err = db.Prepare("UPDATE [users] SET [posts] = [posts] + ? WHERE [uid] = ?") + stmts.incrementUserPosts, err = db.Prepare("UPDATE [users] SET [posts] = [posts] + ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [posts] = [posts] + ? WHERE [uid] = ?") return err } log.Print("Preparing incrementUserBigposts statement.") - incrementUserBigpostsStmt, err = db.Prepare("UPDATE [users] SET [posts] = [posts] + ?,[bigposts] = [bigposts] + ? WHERE [uid] = ?") + stmts.incrementUserBigposts, err = db.Prepare("UPDATE [users] SET [posts] = [posts] + ?,[bigposts] = [bigposts] + ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [posts] = [posts] + ?,[bigposts] = [bigposts] + ? WHERE [uid] = ?") return err } log.Print("Preparing incrementUserMegaposts statement.") - incrementUserMegapostsStmt, err = db.Prepare("UPDATE [users] SET [posts] = [posts] + ?,[bigposts] = [bigposts] + ?,[megaposts] = [megaposts] + ? WHERE [uid] = ?") + stmts.incrementUserMegaposts, err = db.Prepare("UPDATE [users] SET [posts] = [posts] + ?,[bigposts] = [bigposts] + ?,[megaposts] = [megaposts] + ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [posts] = [posts] + ?,[bigposts] = [bigposts] + ?,[megaposts] = [megaposts] + ? WHERE [uid] = ?") return err } log.Print("Preparing incrementUserTopics statement.") - incrementUserTopicsStmt, err = db.Prepare("UPDATE [users] SET [topics] = [topics] + ? WHERE [uid] = ?") + stmts.incrementUserTopics, err = db.Prepare("UPDATE [users] SET [topics] = [topics] + ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [topics] = [topics] + ? WHERE [uid] = ?") return err } log.Print("Preparing editProfileReply statement.") - editProfileReplyStmt, err = db.Prepare("UPDATE [users_replies] SET [content] = ?,[parsed_content] = ? WHERE [rid] = ?") + stmts.editProfileReply, err = db.Prepare("UPDATE [users_replies] SET [content] = ?,[parsed_content] = ? WHERE [rid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users_replies] SET [content] = ?,[parsed_content] = ? WHERE [rid] = ?") return err } log.Print("Preparing updateForum statement.") - updateForumStmt, err = db.Prepare("UPDATE [forums] SET [name] = ?,[desc] = ?,[active] = ?,[preset] = ? WHERE [fid] = ?") + stmts.updateForum, err = db.Prepare("UPDATE [forums] SET [name] = ?,[desc] = ?,[active] = ?,[preset] = ? WHERE [fid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [forums] SET [name] = ?,[desc] = ?,[active] = ?,[preset] = ? WHERE [fid] = ?") return err } log.Print("Preparing updateSetting statement.") - updateSettingStmt, err = db.Prepare("UPDATE [settings] SET [content] = ? WHERE [name] = ?") + stmts.updateSetting, err = db.Prepare("UPDATE [settings] SET [content] = ? WHERE [name] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [settings] SET [content] = ? WHERE [name] = ?") return err } log.Print("Preparing updatePlugin statement.") - updatePluginStmt, err = db.Prepare("UPDATE [plugins] SET [active] = ? WHERE [uname] = ?") + stmts.updatePlugin, err = db.Prepare("UPDATE [plugins] SET [active] = ? WHERE [uname] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [plugins] SET [active] = ? WHERE [uname] = ?") return err } log.Print("Preparing updatePluginInstall statement.") - updatePluginInstallStmt, err = db.Prepare("UPDATE [plugins] SET [installed] = ? WHERE [uname] = ?") + stmts.updatePluginInstall, err = db.Prepare("UPDATE [plugins] SET [installed] = ? WHERE [uname] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [plugins] SET [installed] = ? WHERE [uname] = ?") return err } log.Print("Preparing updateTheme statement.") - updateThemeStmt, err = db.Prepare("UPDATE [themes] SET [default] = ? WHERE [uname] = ?") + stmts.updateTheme, err = db.Prepare("UPDATE [themes] SET [default] = ? WHERE [uname] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [themes] SET [default] = ? WHERE [uname] = ?") return err } log.Print("Preparing updateUser statement.") - updateUserStmt, err = db.Prepare("UPDATE [users] SET [name] = ?,[email] = ?,[group] = ? WHERE [uid] = ?") + stmts.updateUser, err = db.Prepare("UPDATE [users] SET [name] = ?,[email] = ?,[group] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [name] = ?,[email] = ?,[group] = ? WHERE [uid] = ?") return err } log.Print("Preparing updateUserGroup statement.") - updateUserGroupStmt, err = db.Prepare("UPDATE [users] SET [group] = ? WHERE [uid] = ?") + stmts.updateUserGroup, err = db.Prepare("UPDATE [users] SET [group] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [group] = ? WHERE [uid] = ?") return err } log.Print("Preparing updateGroupPerms statement.") - updateGroupPermsStmt, err = db.Prepare("UPDATE [users_groups] SET [permissions] = ? WHERE [gid] = ?") + stmts.updateGroupPerms, err = db.Prepare("UPDATE [users_groups] SET [permissions] = ? WHERE [gid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users_groups] SET [permissions] = ? WHERE [gid] = ?") return err } log.Print("Preparing updateGroupRank statement.") - updateGroupRankStmt, err = db.Prepare("UPDATE [users_groups] SET [is_admin] = ?,[is_mod] = ?,[is_banned] = ? WHERE [gid] = ?") + stmts.updateGroupRank, err = db.Prepare("UPDATE [users_groups] SET [is_admin] = ?,[is_mod] = ?,[is_banned] = ? WHERE [gid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users_groups] SET [is_admin] = ?,[is_mod] = ?,[is_banned] = ? WHERE [gid] = ?") return err } log.Print("Preparing updateGroup statement.") - updateGroupStmt, err = db.Prepare("UPDATE [users_groups] SET [name] = ?,[tag] = ? WHERE [gid] = ?") + stmts.updateGroup, err = db.Prepare("UPDATE [users_groups] SET [name] = ?,[tag] = ? WHERE [gid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users_groups] SET [name] = ?,[tag] = ? WHERE [gid] = ?") return err } log.Print("Preparing updateEmail statement.") - updateEmailStmt, err = db.Prepare("UPDATE [emails] SET [email] = ?,[uid] = ?,[validated] = ?,[token] = ? WHERE [email] = ?") + stmts.updateEmail, err = db.Prepare("UPDATE [emails] SET [email] = ?,[uid] = ?,[validated] = ?,[token] = ? WHERE [email] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [emails] SET [email] = ?,[uid] = ?,[validated] = ?,[token] = ? WHERE [email] = ?") return err } log.Print("Preparing verifyEmail statement.") - verifyEmailStmt, err = db.Prepare("UPDATE [emails] SET [validated] = 1,[token] = '' WHERE [email] = ?") + stmts.verifyEmail, err = db.Prepare("UPDATE [emails] SET [validated] = 1,[token] = '' WHERE [email] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [emails] SET [validated] = 1,[token] = '' WHERE [email] = ?") return err } log.Print("Preparing setTempGroup statement.") - setTempGroupStmt, err = db.Prepare("UPDATE [users] SET [temp_group] = ? WHERE [uid] = ?") + stmts.setTempGroup, err = db.Prepare("UPDATE [users] SET [temp_group] = ? WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [users] SET [temp_group] = ? WHERE [uid] = ?") return err } log.Print("Preparing updateWordFilter statement.") - updateWordFilterStmt, err = db.Prepare("UPDATE [word_filters] SET [find] = ?,[replacement] = ? WHERE [wfid] = ?") + stmts.updateWordFilter, err = db.Prepare("UPDATE [word_filters] SET [find] = ?,[replacement] = ? WHERE [wfid] = ?") if err != nil { log.Print("Bad Query: ","UPDATE [word_filters] SET [find] = ?,[replacement] = ? WHERE [wfid] = ?") return err } log.Print("Preparing bumpSync statement.") - bumpSyncStmt, err = db.Prepare("UPDATE [sync] SET [last_update] = GETUTCDATE()") + stmts.bumpSync, err = db.Prepare("UPDATE [sync] SET [last_update] = GETUTCDATE()") if err != nil { log.Print("Bad Query: ","UPDATE [sync] SET [last_update] = GETUTCDATE()") return err } log.Print("Preparing deleteUser statement.") - deleteUserStmt, err = db.Prepare("DELETE FROM [users] WHERE [uid] = ?") + stmts.deleteUser, err = db.Prepare("DELETE FROM [users] WHERE [uid] = ?") if err != nil { log.Print("Bad Query: ","DELETE FROM [users] WHERE [uid] = ?") return err } log.Print("Preparing deleteTopic statement.") - deleteTopicStmt, err = db.Prepare("DELETE FROM [topics] WHERE [tid] = ?") + stmts.deleteTopic, err = db.Prepare("DELETE FROM [topics] WHERE [tid] = ?") if err != nil { log.Print("Bad Query: ","DELETE FROM [topics] WHERE [tid] = ?") return err } log.Print("Preparing deleteReply statement.") - deleteReplyStmt, err = db.Prepare("DELETE FROM [replies] WHERE [rid] = ?") + stmts.deleteReply, err = db.Prepare("DELETE FROM [replies] WHERE [rid] = ?") if err != nil { log.Print("Bad Query: ","DELETE FROM [replies] WHERE [rid] = ?") return err } log.Print("Preparing deleteProfileReply statement.") - deleteProfileReplyStmt, err = db.Prepare("DELETE FROM [users_replies] WHERE [rid] = ?") + stmts.deleteProfileReply, err = db.Prepare("DELETE FROM [users_replies] WHERE [rid] = ?") if err != nil { log.Print("Bad Query: ","DELETE FROM [users_replies] WHERE [rid] = ?") return err } log.Print("Preparing deleteActivityStreamMatch statement.") - deleteActivityStreamMatchStmt, err = db.Prepare("DELETE FROM [activity_stream_matches] WHERE [watcher] = ? AND [asid] = ?") + stmts.deleteActivityStreamMatch, err = db.Prepare("DELETE FROM [activity_stream_matches] WHERE [watcher] = ? AND [asid] = ?") if err != nil { log.Print("Bad Query: ","DELETE FROM [activity_stream_matches] WHERE [watcher] = ? AND [asid] = ?") return err } log.Print("Preparing deleteWordFilter statement.") - deleteWordFilterStmt, err = db.Prepare("DELETE FROM [word_filters] WHERE [wfid] = ?") + stmts.deleteWordFilter, err = db.Prepare("DELETE FROM [word_filters] WHERE [wfid] = ?") if err != nil { log.Print("Bad Query: ","DELETE FROM [word_filters] WHERE [wfid] = ?") return err } log.Print("Preparing reportExists statement.") - reportExistsStmt, err = db.Prepare("SELECT COUNT(*) AS [count] FROM [topics] WHERE [data] = ? AND [data] != '' AND [parentID] = 1") + stmts.reportExists, err = db.Prepare("SELECT COUNT(*) AS [count] FROM [topics] WHERE [data] = ? AND [data] != '' AND [parentID] = 1") if err != nil { log.Print("Bad Query: ","SELECT COUNT(*) AS [count] FROM [topics] WHERE [data] = ? AND [data] != '' AND [parentID] = 1") return err } log.Print("Preparing groupCount statement.") - groupCountStmt, err = db.Prepare("SELECT COUNT(*) AS [count] FROM [users_groups]") + stmts.groupCount, err = db.Prepare("SELECT COUNT(*) AS [count] FROM [users_groups]") if err != nil { log.Print("Bad Query: ","SELECT COUNT(*) AS [count] FROM [users_groups]") return err } log.Print("Preparing modlogCount statement.") - modlogCountStmt, err = db.Prepare("SELECT COUNT(*) AS [count] FROM [moderation_logs]") + stmts.modlogCount, err = db.Prepare("SELECT COUNT(*) AS [count] FROM [moderation_logs]") if err != nil { log.Print("Bad Query: ","SELECT COUNT(*) AS [count] FROM [moderation_logs]") return err } log.Print("Preparing notifyWatchers statement.") - notifyWatchersStmt, err = db.Prepare("INSERT INTO [activity_stream_matches] ([watcher],[asid]) SELECT [activity_subscriptions].[user],[activity_stream].[asid] FROM [activity_stream] INNER JOIN [activity_subscriptions] ON [activity_subscriptions].[targetType] = [activity_stream].[elementType] AND [activity_subscriptions].[targetID] = [activity_stream].[elementID] AND [activity_subscriptions].[user] != [activity_stream].[actor] WHERE [asid] = ?1") + stmts.notifyWatchers, err = db.Prepare("INSERT INTO [activity_stream_matches] ([watcher],[asid]) SELECT [activity_subscriptions].[user],[activity_stream].[asid] FROM [activity_stream] INNER JOIN [activity_subscriptions] ON [activity_subscriptions].[targetType] = [activity_stream].[elementType] AND [activity_subscriptions].[targetID] = [activity_stream].[elementID] AND [activity_subscriptions].[user] != [activity_stream].[actor] WHERE [asid] = ?1") if err != nil { log.Print("Bad Query: ","INSERT INTO [activity_stream_matches] ([watcher],[asid]) SELECT [activity_subscriptions].[user],[activity_stream].[asid] FROM [activity_stream] INNER JOIN [activity_subscriptions] ON [activity_subscriptions].[targetType] = [activity_stream].[elementType] AND [activity_subscriptions].[targetID] = [activity_stream].[elementID] AND [activity_subscriptions].[user] != [activity_stream].[actor] WHERE [asid] = ?1") return err diff --git a/gen_mysql.go b/gen_mysql.go index b68dc088..51e304d6 100644 --- a/gen_mysql.go +++ b/gen_mysql.go @@ -9,118 +9,132 @@ import "database/sql" //import "./query_gen/lib" // nolint -var getReplyStmt *sql.Stmt -var getUserReplyStmt *sql.Stmt -var getPasswordStmt *sql.Stmt -var getSettingsStmt *sql.Stmt -var getSettingStmt *sql.Stmt -var getFullSettingStmt *sql.Stmt -var getFullSettingsStmt *sql.Stmt -var getGroupsStmt *sql.Stmt -var getForumsStmt *sql.Stmt -var getForumsPermissionsStmt *sql.Stmt -var getPluginsStmt *sql.Stmt -var getThemesStmt *sql.Stmt -var getWidgetsStmt *sql.Stmt -var isPluginActiveStmt *sql.Stmt -var getUsersOffsetStmt *sql.Stmt -var getWordFiltersStmt *sql.Stmt -var isThemeDefaultStmt *sql.Stmt -var getModlogsStmt *sql.Stmt -var getModlogsOffsetStmt *sql.Stmt -var getReplyTIDStmt *sql.Stmt -var getTopicFIDStmt *sql.Stmt -var getUserReplyUIDStmt *sql.Stmt -var hasLikedTopicStmt *sql.Stmt -var hasLikedReplyStmt *sql.Stmt -var getUserNameStmt *sql.Stmt -var getEmailsByUserStmt *sql.Stmt -var getTopicBasicStmt *sql.Stmt -var getActivityEntryStmt *sql.Stmt -var forumEntryExistsStmt *sql.Stmt -var groupEntryExistsStmt *sql.Stmt -var getForumTopicsOffsetStmt *sql.Stmt -var getExpiredScheduledGroupsStmt *sql.Stmt -var getSyncStmt *sql.Stmt -var getAttachmentStmt *sql.Stmt -var getTopicRepliesOffsetStmt *sql.Stmt -var getTopicListStmt *sql.Stmt -var getTopicUserStmt *sql.Stmt -var getTopicByReplyStmt *sql.Stmt -var getTopicRepliesStmt *sql.Stmt -var getForumTopicsStmt *sql.Stmt -var getProfileRepliesStmt *sql.Stmt -var getWatchersStmt *sql.Stmt -var createTopicStmt *sql.Stmt -var createReportStmt *sql.Stmt -var createReplyStmt *sql.Stmt -var createActionReplyStmt *sql.Stmt -var createLikeStmt *sql.Stmt -var addActivityStmt *sql.Stmt -var notifyOneStmt *sql.Stmt -var addEmailStmt *sql.Stmt -var createProfileReplyStmt *sql.Stmt -var addSubscriptionStmt *sql.Stmt -var createForumStmt *sql.Stmt -var addForumPermsToForumStmt *sql.Stmt -var addPluginStmt *sql.Stmt -var addThemeStmt *sql.Stmt -var addModlogEntryStmt *sql.Stmt -var addAdminlogEntryStmt *sql.Stmt -var addAttachmentStmt *sql.Stmt -var createWordFilterStmt *sql.Stmt -var addRepliesToTopicStmt *sql.Stmt -var removeRepliesFromTopicStmt *sql.Stmt -var addTopicsToForumStmt *sql.Stmt -var removeTopicsFromForumStmt *sql.Stmt -var updateForumCacheStmt *sql.Stmt -var addLikesToTopicStmt *sql.Stmt -var addLikesToReplyStmt *sql.Stmt -var editTopicStmt *sql.Stmt -var editReplyStmt *sql.Stmt -var stickTopicStmt *sql.Stmt -var unstickTopicStmt *sql.Stmt -var lockTopicStmt *sql.Stmt -var unlockTopicStmt *sql.Stmt -var updateLastIPStmt *sql.Stmt -var updateSessionStmt *sql.Stmt -var setPasswordStmt *sql.Stmt -var setAvatarStmt *sql.Stmt -var setUsernameStmt *sql.Stmt -var changeGroupStmt *sql.Stmt -var activateUserStmt *sql.Stmt -var updateUserLevelStmt *sql.Stmt -var incrementUserScoreStmt *sql.Stmt -var incrementUserPostsStmt *sql.Stmt -var incrementUserBigpostsStmt *sql.Stmt -var incrementUserMegapostsStmt *sql.Stmt -var incrementUserTopicsStmt *sql.Stmt -var editProfileReplyStmt *sql.Stmt -var updateForumStmt *sql.Stmt -var updateSettingStmt *sql.Stmt -var updatePluginStmt *sql.Stmt -var updatePluginInstallStmt *sql.Stmt -var updateThemeStmt *sql.Stmt -var updateUserStmt *sql.Stmt -var updateUserGroupStmt *sql.Stmt -var updateGroupPermsStmt *sql.Stmt -var updateGroupRankStmt *sql.Stmt -var updateGroupStmt *sql.Stmt -var updateEmailStmt *sql.Stmt -var verifyEmailStmt *sql.Stmt -var setTempGroupStmt *sql.Stmt -var updateWordFilterStmt *sql.Stmt -var bumpSyncStmt *sql.Stmt -var deleteUserStmt *sql.Stmt -var deleteTopicStmt *sql.Stmt -var deleteReplyStmt *sql.Stmt -var deleteProfileReplyStmt *sql.Stmt -var deleteActivityStreamMatchStmt *sql.Stmt -var deleteWordFilterStmt *sql.Stmt -var reportExistsStmt *sql.Stmt -var groupCountStmt *sql.Stmt -var modlogCountStmt *sql.Stmt -var notifyWatchersStmt *sql.Stmt +type Stmts struct { + getReply *sql.Stmt + getUserReply *sql.Stmt + getPassword *sql.Stmt + getSettings *sql.Stmt + getSetting *sql.Stmt + getFullSetting *sql.Stmt + getFullSettings *sql.Stmt + getGroups *sql.Stmt + getForums *sql.Stmt + getForumsPermissions *sql.Stmt + getPlugins *sql.Stmt + getThemes *sql.Stmt + getWidgets *sql.Stmt + isPluginActive *sql.Stmt + getUsersOffset *sql.Stmt + getWordFilters *sql.Stmt + isThemeDefault *sql.Stmt + getModlogs *sql.Stmt + getModlogsOffset *sql.Stmt + getReplyTID *sql.Stmt + getTopicFID *sql.Stmt + getUserReplyUID *sql.Stmt + hasLikedTopic *sql.Stmt + hasLikedReply *sql.Stmt + getUserName *sql.Stmt + getEmailsByUser *sql.Stmt + getTopicBasic *sql.Stmt + getActivityEntry *sql.Stmt + forumEntryExists *sql.Stmt + groupEntryExists *sql.Stmt + getForumTopicsOffset *sql.Stmt + getExpiredScheduledGroups *sql.Stmt + getSync *sql.Stmt + getAttachment *sql.Stmt + getTopicRepliesOffset *sql.Stmt + getTopicList *sql.Stmt + getTopicUser *sql.Stmt + getTopicByReply *sql.Stmt + getTopicReplies *sql.Stmt + getForumTopics *sql.Stmt + getProfileReplies *sql.Stmt + getWatchers *sql.Stmt + createTopic *sql.Stmt + createReport *sql.Stmt + createReply *sql.Stmt + createActionReply *sql.Stmt + createLike *sql.Stmt + addActivity *sql.Stmt + notifyOne *sql.Stmt + addEmail *sql.Stmt + createProfileReply *sql.Stmt + addSubscription *sql.Stmt + createForum *sql.Stmt + addForumPermsToForum *sql.Stmt + addPlugin *sql.Stmt + addTheme *sql.Stmt + addModlogEntry *sql.Stmt + addAdminlogEntry *sql.Stmt + addAttachment *sql.Stmt + createWordFilter *sql.Stmt + addRepliesToTopic *sql.Stmt + removeRepliesFromTopic *sql.Stmt + addTopicsToForum *sql.Stmt + removeTopicsFromForum *sql.Stmt + updateForumCache *sql.Stmt + addLikesToTopic *sql.Stmt + addLikesToReply *sql.Stmt + editTopic *sql.Stmt + editReply *sql.Stmt + stickTopic *sql.Stmt + unstickTopic *sql.Stmt + lockTopic *sql.Stmt + unlockTopic *sql.Stmt + updateLastIP *sql.Stmt + updateSession *sql.Stmt + setPassword *sql.Stmt + setAvatar *sql.Stmt + setUsername *sql.Stmt + changeGroup *sql.Stmt + activateUser *sql.Stmt + updateUserLevel *sql.Stmt + incrementUserScore *sql.Stmt + incrementUserPosts *sql.Stmt + incrementUserBigposts *sql.Stmt + incrementUserMegaposts *sql.Stmt + incrementUserTopics *sql.Stmt + editProfileReply *sql.Stmt + updateForum *sql.Stmt + updateSetting *sql.Stmt + updatePlugin *sql.Stmt + updatePluginInstall *sql.Stmt + updateTheme *sql.Stmt + updateUser *sql.Stmt + updateUserGroup *sql.Stmt + updateGroupPerms *sql.Stmt + updateGroupRank *sql.Stmt + updateGroup *sql.Stmt + updateEmail *sql.Stmt + verifyEmail *sql.Stmt + setTempGroup *sql.Stmt + updateWordFilter *sql.Stmt + bumpSync *sql.Stmt + deleteUser *sql.Stmt + deleteTopic *sql.Stmt + deleteReply *sql.Stmt + deleteProfileReply *sql.Stmt + deleteActivityStreamMatch *sql.Stmt + deleteWordFilter *sql.Stmt + reportExists *sql.Stmt + groupCount *sql.Stmt + modlogCount *sql.Stmt + notifyWatchers *sql.Stmt + + getActivityFeedByWatcher *sql.Stmt + getActivityCountByWatcher *sql.Stmt + todaysPostCount *sql.Stmt + todaysTopicCount *sql.Stmt + todaysReportCount *sql.Stmt + todaysNewUserCount *sql.Stmt + findUsersByIPUsers *sql.Stmt + findUsersByIPTopics *sql.Stmt + findUsersByIPReplies *sql.Stmt + + Mocks bool +} // nolint func _gen_mysql() (err error) { @@ -129,673 +143,673 @@ func _gen_mysql() (err error) { } log.Print("Preparing getReply statement.") - getReplyStmt, err = db.Prepare("SELECT `tid`,`content`,`createdBy`,`createdAt`,`lastEdit`,`lastEditBy`,`ipaddress`,`likeCount` FROM `replies` WHERE `rid` = ?") + stmts.getReply, err = db.Prepare("SELECT `tid`,`content`,`createdBy`,`createdAt`,`lastEdit`,`lastEditBy`,`ipaddress`,`likeCount` FROM `replies` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing getUserReply statement.") - getUserReplyStmt, err = db.Prepare("SELECT `uid`,`content`,`createdBy`,`createdAt`,`lastEdit`,`lastEditBy`,`ipaddress` FROM `users_replies` WHERE `rid` = ?") + stmts.getUserReply, err = db.Prepare("SELECT `uid`,`content`,`createdBy`,`createdAt`,`lastEdit`,`lastEditBy`,`ipaddress` FROM `users_replies` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing getPassword statement.") - getPasswordStmt, err = db.Prepare("SELECT `password`,`salt` FROM `users` WHERE `uid` = ?") + stmts.getPassword, err = db.Prepare("SELECT `password`,`salt` FROM `users` WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing getSettings statement.") - getSettingsStmt, err = db.Prepare("SELECT `name`,`content`,`type` FROM `settings`") + stmts.getSettings, err = db.Prepare("SELECT `name`,`content`,`type` FROM `settings`") if err != nil { return err } log.Print("Preparing getSetting statement.") - getSettingStmt, err = db.Prepare("SELECT `content`,`type` FROM `settings` WHERE `name` = ?") + stmts.getSetting, err = db.Prepare("SELECT `content`,`type` FROM `settings` WHERE `name` = ?") if err != nil { return err } log.Print("Preparing getFullSetting statement.") - getFullSettingStmt, err = db.Prepare("SELECT `name`,`type`,`constraints` FROM `settings` WHERE `name` = ?") + stmts.getFullSetting, err = db.Prepare("SELECT `name`,`type`,`constraints` FROM `settings` WHERE `name` = ?") if err != nil { return err } log.Print("Preparing getFullSettings statement.") - getFullSettingsStmt, err = db.Prepare("SELECT `name`,`content`,`type`,`constraints` FROM `settings`") + stmts.getFullSettings, err = db.Prepare("SELECT `name`,`content`,`type`,`constraints` FROM `settings`") if err != nil { return err } log.Print("Preparing getGroups statement.") - getGroupsStmt, err = db.Prepare("SELECT `gid`,`name`,`permissions`,`plugin_perms`,`is_mod`,`is_admin`,`is_banned`,`tag` FROM `users_groups`") + stmts.getGroups, err = db.Prepare("SELECT `gid`,`name`,`permissions`,`plugin_perms`,`is_mod`,`is_admin`,`is_banned`,`tag` FROM `users_groups`") if err != nil { return err } log.Print("Preparing getForums statement.") - getForumsStmt, err = db.Prepare("SELECT `fid`,`name`,`desc`,`active`,`preset`,`parentID`,`parentType`,`topicCount`,`lastTopicID`,`lastReplyerID` FROM `forums` ORDER BY fid ASC") + stmts.getForums, err = db.Prepare("SELECT `fid`,`name`,`desc`,`active`,`preset`,`parentID`,`parentType`,`topicCount`,`lastTopicID`,`lastReplyerID` FROM `forums` ORDER BY fid ASC") if err != nil { return err } log.Print("Preparing getForumsPermissions statement.") - getForumsPermissionsStmt, err = db.Prepare("SELECT `gid`,`fid`,`permissions` FROM `forums_permissions` ORDER BY gid ASC,fid ASC") + stmts.getForumsPermissions, err = db.Prepare("SELECT `gid`,`fid`,`permissions` FROM `forums_permissions` ORDER BY gid ASC,fid ASC") if err != nil { return err } log.Print("Preparing getPlugins statement.") - getPluginsStmt, err = db.Prepare("SELECT `uname`,`active`,`installed` FROM `plugins`") + stmts.getPlugins, err = db.Prepare("SELECT `uname`,`active`,`installed` FROM `plugins`") if err != nil { return err } log.Print("Preparing getThemes statement.") - getThemesStmt, err = db.Prepare("SELECT `uname`,`default` FROM `themes`") + stmts.getThemes, err = db.Prepare("SELECT `uname`,`default` FROM `themes`") if err != nil { return err } log.Print("Preparing getWidgets statement.") - getWidgetsStmt, err = db.Prepare("SELECT `position`,`side`,`type`,`active`,`location`,`data` FROM `widgets` ORDER BY position ASC") + stmts.getWidgets, err = db.Prepare("SELECT `position`,`side`,`type`,`active`,`location`,`data` FROM `widgets` ORDER BY position ASC") if err != nil { return err } log.Print("Preparing isPluginActive statement.") - isPluginActiveStmt, err = db.Prepare("SELECT `active` FROM `plugins` WHERE `uname` = ?") + stmts.isPluginActive, err = db.Prepare("SELECT `active` FROM `plugins` WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing getUsersOffset statement.") - getUsersOffsetStmt, err = db.Prepare("SELECT `uid`,`name`,`group`,`active`,`is_super_admin`,`avatar` FROM `users` ORDER BY uid ASC LIMIT ?,?") + stmts.getUsersOffset, err = db.Prepare("SELECT `uid`,`name`,`group`,`active`,`is_super_admin`,`avatar` FROM `users` ORDER BY uid ASC LIMIT ?,?") if err != nil { return err } log.Print("Preparing getWordFilters statement.") - getWordFiltersStmt, err = db.Prepare("SELECT `wfid`,`find`,`replacement` FROM `word_filters`") + stmts.getWordFilters, err = db.Prepare("SELECT `wfid`,`find`,`replacement` FROM `word_filters`") if err != nil { return err } log.Print("Preparing isThemeDefault statement.") - isThemeDefaultStmt, err = db.Prepare("SELECT `default` FROM `themes` WHERE `uname` = ?") + stmts.isThemeDefault, err = db.Prepare("SELECT `default` FROM `themes` WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing getModlogs statement.") - getModlogsStmt, err = db.Prepare("SELECT `action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt` FROM `moderation_logs`") + stmts.getModlogs, err = db.Prepare("SELECT `action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt` FROM `moderation_logs`") if err != nil { return err } log.Print("Preparing getModlogsOffset statement.") - getModlogsOffsetStmt, err = db.Prepare("SELECT `action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt` FROM `moderation_logs` ORDER BY doneAt DESC LIMIT ?,?") + stmts.getModlogsOffset, err = db.Prepare("SELECT `action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt` FROM `moderation_logs` ORDER BY doneAt DESC LIMIT ?,?") if err != nil { return err } log.Print("Preparing getReplyTID statement.") - getReplyTIDStmt, err = db.Prepare("SELECT `tid` FROM `replies` WHERE `rid` = ?") + stmts.getReplyTID, err = db.Prepare("SELECT `tid` FROM `replies` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing getTopicFID statement.") - getTopicFIDStmt, err = db.Prepare("SELECT `parentID` FROM `topics` WHERE `tid` = ?") + stmts.getTopicFID, err = db.Prepare("SELECT `parentID` FROM `topics` WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing getUserReplyUID statement.") - getUserReplyUIDStmt, err = db.Prepare("SELECT `uid` FROM `users_replies` WHERE `rid` = ?") + stmts.getUserReplyUID, err = db.Prepare("SELECT `uid` FROM `users_replies` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing hasLikedTopic statement.") - hasLikedTopicStmt, err = db.Prepare("SELECT `targetItem` FROM `likes` WHERE `sentBy` = ? AND `targetItem` = ? AND `targetType` = 'topics'") + stmts.hasLikedTopic, err = db.Prepare("SELECT `targetItem` FROM `likes` WHERE `sentBy` = ? AND `targetItem` = ? AND `targetType` = 'topics'") if err != nil { return err } log.Print("Preparing hasLikedReply statement.") - hasLikedReplyStmt, err = db.Prepare("SELECT `targetItem` FROM `likes` WHERE `sentBy` = ? AND `targetItem` = ? AND `targetType` = 'replies'") + stmts.hasLikedReply, err = db.Prepare("SELECT `targetItem` FROM `likes` WHERE `sentBy` = ? AND `targetItem` = ? AND `targetType` = 'replies'") if err != nil { return err } log.Print("Preparing getUserName statement.") - getUserNameStmt, err = db.Prepare("SELECT `name` FROM `users` WHERE `uid` = ?") + stmts.getUserName, err = db.Prepare("SELECT `name` FROM `users` WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing getEmailsByUser statement.") - getEmailsByUserStmt, err = db.Prepare("SELECT `email`,`validated`,`token` FROM `emails` WHERE `uid` = ?") + stmts.getEmailsByUser, err = db.Prepare("SELECT `email`,`validated`,`token` FROM `emails` WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing getTopicBasic statement.") - getTopicBasicStmt, err = db.Prepare("SELECT `title`,`content` FROM `topics` WHERE `tid` = ?") + stmts.getTopicBasic, err = db.Prepare("SELECT `title`,`content` FROM `topics` WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing getActivityEntry statement.") - getActivityEntryStmt, err = db.Prepare("SELECT `actor`,`targetUser`,`event`,`elementType`,`elementID` FROM `activity_stream` WHERE `asid` = ?") + stmts.getActivityEntry, err = db.Prepare("SELECT `actor`,`targetUser`,`event`,`elementType`,`elementID` FROM `activity_stream` WHERE `asid` = ?") if err != nil { return err } log.Print("Preparing forumEntryExists statement.") - forumEntryExistsStmt, err = db.Prepare("SELECT `fid` FROM `forums` WHERE `name` = '' ORDER BY fid ASC LIMIT 0,1") + stmts.forumEntryExists, err = db.Prepare("SELECT `fid` FROM `forums` WHERE `name` = '' ORDER BY fid ASC LIMIT 0,1") if err != nil { return err } log.Print("Preparing groupEntryExists statement.") - groupEntryExistsStmt, err = db.Prepare("SELECT `gid` FROM `users_groups` WHERE `name` = '' ORDER BY gid ASC LIMIT 0,1") + stmts.groupEntryExists, err = db.Prepare("SELECT `gid` FROM `users_groups` WHERE `name` = '' ORDER BY gid ASC LIMIT 0,1") if err != nil { return err } log.Print("Preparing getForumTopicsOffset statement.") - getForumTopicsOffsetStmt, err = db.Prepare("SELECT `tid`,`title`,`content`,`createdBy`,`is_closed`,`sticky`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`parentID`,`postCount`,`likeCount` FROM `topics` WHERE `parentID` = ? ORDER BY sticky DESC,lastReplyAt DESC,createdBy DESC LIMIT ?,?") + stmts.getForumTopicsOffset, err = db.Prepare("SELECT `tid`,`title`,`content`,`createdBy`,`is_closed`,`sticky`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`parentID`,`postCount`,`likeCount` FROM `topics` WHERE `parentID` = ? ORDER BY sticky DESC,lastReplyAt DESC,createdBy DESC LIMIT ?,?") if err != nil { return err } log.Print("Preparing getExpiredScheduledGroups statement.") - getExpiredScheduledGroupsStmt, err = db.Prepare("SELECT `uid` FROM `users_groups_scheduler` WHERE UTC_TIMESTAMP() > `revert_at` AND `temporary` = 1") + stmts.getExpiredScheduledGroups, err = db.Prepare("SELECT `uid` FROM `users_groups_scheduler` WHERE UTC_TIMESTAMP() > `revert_at` AND `temporary` = 1") if err != nil { return err } log.Print("Preparing getSync statement.") - getSyncStmt, err = db.Prepare("SELECT `last_update` FROM `sync`") + stmts.getSync, err = db.Prepare("SELECT `last_update` FROM `sync`") if err != nil { return err } log.Print("Preparing getAttachment statement.") - getAttachmentStmt, err = db.Prepare("SELECT `sectionID`,`sectionTable`,`originID`,`originTable`,`uploadedBy`,`path` FROM `attachments` WHERE `path` = ? AND `sectionID` = ? AND `sectionTable` = ?") + stmts.getAttachment, err = db.Prepare("SELECT `sectionID`,`sectionTable`,`originID`,`originTable`,`uploadedBy`,`path` FROM `attachments` WHERE `path` = ? AND `sectionID` = ? AND `sectionTable` = ?") if err != nil { return err } log.Print("Preparing getTopicRepliesOffset statement.") - getTopicRepliesOffsetStmt, err = db.Prepare("SELECT `replies`.`rid`, `replies`.`content`, `replies`.`createdBy`, `replies`.`createdAt`, `replies`.`lastEdit`, `replies`.`lastEditBy`, `users`.`avatar`, `users`.`name`, `users`.`group`, `users`.`url_prefix`, `users`.`url_name`, `users`.`level`, `replies`.`ipaddress`, `replies`.`likeCount`, `replies`.`actionType` FROM `replies` LEFT JOIN `users` ON `replies`.`createdBy` = `users`.`uid` WHERE `replies`.`tid` = ? ORDER BY replies.rid ASC LIMIT ?,?") + stmts.getTopicRepliesOffset, err = db.Prepare("SELECT `replies`.`rid`, `replies`.`content`, `replies`.`createdBy`, `replies`.`createdAt`, `replies`.`lastEdit`, `replies`.`lastEditBy`, `users`.`avatar`, `users`.`name`, `users`.`group`, `users`.`url_prefix`, `users`.`url_name`, `users`.`level`, `replies`.`ipaddress`, `replies`.`likeCount`, `replies`.`actionType` FROM `replies` LEFT JOIN `users` ON `replies`.`createdBy` = `users`.`uid` WHERE `replies`.`tid` = ? ORDER BY replies.rid ASC LIMIT ?,?") if err != nil { return err } log.Print("Preparing getTopicList statement.") - getTopicListStmt, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`createdAt`, `topics`.`parentID`, `users`.`name`, `users`.`avatar` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") + stmts.getTopicList, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`createdAt`, `topics`.`parentID`, `users`.`name`, `users`.`avatar` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") if err != nil { return err } log.Print("Preparing getTopicUser statement.") - getTopicUserStmt, err = db.Prepare("SELECT `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`createdAt`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`parentID`, `topics`.`ipaddress`, `topics`.`postCount`, `topics`.`likeCount`, `users`.`name`, `users`.`avatar`, `users`.`group`, `users`.`url_prefix`, `users`.`url_name`, `users`.`level` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` WHERE `tid` = ?") + stmts.getTopicUser, err = db.Prepare("SELECT `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`createdAt`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`parentID`, `topics`.`ipaddress`, `topics`.`postCount`, `topics`.`likeCount`, `users`.`name`, `users`.`avatar`, `users`.`group`, `users`.`url_prefix`, `users`.`url_name`, `users`.`level` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing getTopicByReply statement.") - getTopicByReplyStmt, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`createdAt`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`parentID`, `topics`.`ipaddress`, `topics`.`postCount`, `topics`.`likeCount`, `topics`.`data` FROM `replies` LEFT JOIN `topics` ON `replies`.`tid` = `topics`.`tid` WHERE `rid` = ?") + stmts.getTopicByReply, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`createdAt`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`parentID`, `topics`.`ipaddress`, `topics`.`postCount`, `topics`.`likeCount`, `topics`.`data` FROM `replies` LEFT JOIN `topics` ON `replies`.`tid` = `topics`.`tid` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing getTopicReplies statement.") - getTopicRepliesStmt, err = db.Prepare("SELECT `replies`.`rid`, `replies`.`content`, `replies`.`createdBy`, `replies`.`createdAt`, `replies`.`lastEdit`, `replies`.`lastEditBy`, `users`.`avatar`, `users`.`name`, `users`.`group`, `users`.`url_prefix`, `users`.`url_name`, `users`.`level`, `replies`.`ipaddress` FROM `replies` LEFT JOIN `users` ON `replies`.`createdBy` = `users`.`uid` WHERE `tid` = ?") + stmts.getTopicReplies, err = db.Prepare("SELECT `replies`.`rid`, `replies`.`content`, `replies`.`createdBy`, `replies`.`createdAt`, `replies`.`lastEdit`, `replies`.`lastEditBy`, `users`.`avatar`, `users`.`name`, `users`.`group`, `users`.`url_prefix`, `users`.`url_name`, `users`.`level`, `replies`.`ipaddress` FROM `replies` LEFT JOIN `users` ON `replies`.`createdBy` = `users`.`uid` WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing getForumTopics statement.") - getForumTopicsStmt, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`createdAt`, `topics`.`lastReplyAt`, `topics`.`parentID`, `users`.`name`, `users`.`avatar` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` WHERE `topics`.`parentID` = ? ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") + stmts.getForumTopics, err = db.Prepare("SELECT `topics`.`tid`, `topics`.`title`, `topics`.`content`, `topics`.`createdBy`, `topics`.`is_closed`, `topics`.`sticky`, `topics`.`createdAt`, `topics`.`lastReplyAt`, `topics`.`parentID`, `users`.`name`, `users`.`avatar` FROM `topics` LEFT JOIN `users` ON `topics`.`createdBy` = `users`.`uid` WHERE `topics`.`parentID` = ? ORDER BY topics.sticky DESC,topics.lastReplyAt DESC,topics.createdBy DESC") if err != nil { return err } log.Print("Preparing getProfileReplies statement.") - getProfileRepliesStmt, err = db.Prepare("SELECT `users_replies`.`rid`, `users_replies`.`content`, `users_replies`.`createdBy`, `users_replies`.`createdAt`, `users_replies`.`lastEdit`, `users_replies`.`lastEditBy`, `users`.`avatar`, `users`.`name`, `users`.`group` FROM `users_replies` LEFT JOIN `users` ON `users_replies`.`createdBy` = `users`.`uid` WHERE `users_replies`.`uid` = ?") + stmts.getProfileReplies, err = db.Prepare("SELECT `users_replies`.`rid`, `users_replies`.`content`, `users_replies`.`createdBy`, `users_replies`.`createdAt`, `users_replies`.`lastEdit`, `users_replies`.`lastEditBy`, `users`.`avatar`, `users`.`name`, `users`.`group` FROM `users_replies` LEFT JOIN `users` ON `users_replies`.`createdBy` = `users`.`uid` WHERE `users_replies`.`uid` = ?") if err != nil { return err } log.Print("Preparing getWatchers statement.") - getWatchersStmt, err = db.Prepare("SELECT `activity_subscriptions`.`user` FROM `activity_stream` INNER JOIN `activity_subscriptions` ON `activity_subscriptions`.`targetType` = `activity_stream`.`elementType` AND `activity_subscriptions`.`targetID` = `activity_stream`.`elementID` AND `activity_subscriptions`.`user` != `activity_stream`.`actor` WHERE `asid` = ?") + stmts.getWatchers, err = db.Prepare("SELECT `activity_subscriptions`.`user` FROM `activity_stream` INNER JOIN `activity_subscriptions` ON `activity_subscriptions`.`targetType` = `activity_stream`.`elementType` AND `activity_subscriptions`.`targetID` = `activity_stream`.`elementID` AND `activity_subscriptions`.`user` != `activity_stream`.`actor` WHERE `asid` = ?") if err != nil { return err } log.Print("Preparing createTopic statement.") - createTopicStmt, err = db.Prepare("INSERT INTO `topics`(`parentID`,`title`,`content`,`parsed_content`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`ipaddress`,`words`,`createdBy`) VALUES (?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,?)") + stmts.createTopic, err = db.Prepare("INSERT INTO `topics`(`parentID`,`title`,`content`,`parsed_content`,`createdAt`,`lastReplyAt`,`lastReplyBy`,`ipaddress`,`words`,`createdBy`) VALUES (?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,?)") if err != nil { return err } log.Print("Preparing createReport statement.") - createReportStmt, err = db.Prepare("INSERT INTO `topics`(`title`,`content`,`parsed_content`,`createdAt`,`lastReplyAt`,`createdBy`,`lastReplyBy`,`data`,`parentID`,`css_class`) VALUES (?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,1,'report')") + stmts.createReport, err = db.Prepare("INSERT INTO `topics`(`title`,`content`,`parsed_content`,`createdAt`,`lastReplyAt`,`createdBy`,`lastReplyBy`,`data`,`parentID`,`css_class`) VALUES (?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?,1,'report')") if err != nil { return err } log.Print("Preparing createReply statement.") - createReplyStmt, err = db.Prepare("INSERT INTO `replies`(`tid`,`content`,`parsed_content`,`createdAt`,`lastUpdated`,`ipaddress`,`words`,`createdBy`) VALUES (?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?)") + stmts.createReply, err = db.Prepare("INSERT INTO `replies`(`tid`,`content`,`parsed_content`,`createdAt`,`lastUpdated`,`ipaddress`,`words`,`createdBy`) VALUES (?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),?,?,?)") if err != nil { return err } log.Print("Preparing createActionReply statement.") - createActionReplyStmt, err = db.Prepare("INSERT INTO `replies`(`tid`,`actionType`,`ipaddress`,`createdBy`,`createdAt`,`lastUpdated`,`content`,`parsed_content`) VALUES (?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'','')") + stmts.createActionReply, err = db.Prepare("INSERT INTO `replies`(`tid`,`actionType`,`ipaddress`,`createdBy`,`createdAt`,`lastUpdated`,`content`,`parsed_content`) VALUES (?,?,?,?,UTC_TIMESTAMP(),UTC_TIMESTAMP(),'','')") if err != nil { return err } log.Print("Preparing createLike statement.") - createLikeStmt, err = db.Prepare("INSERT INTO `likes`(`weight`,`targetItem`,`targetType`,`sentBy`) VALUES (?,?,?,?)") + stmts.createLike, err = db.Prepare("INSERT INTO `likes`(`weight`,`targetItem`,`targetType`,`sentBy`) VALUES (?,?,?,?)") if err != nil { return err } log.Print("Preparing addActivity statement.") - addActivityStmt, err = db.Prepare("INSERT INTO `activity_stream`(`actor`,`targetUser`,`event`,`elementType`,`elementID`) VALUES (?,?,?,?,?)") + stmts.addActivity, err = db.Prepare("INSERT INTO `activity_stream`(`actor`,`targetUser`,`event`,`elementType`,`elementID`) VALUES (?,?,?,?,?)") if err != nil { return err } log.Print("Preparing notifyOne statement.") - notifyOneStmt, err = db.Prepare("INSERT INTO `activity_stream_matches`(`watcher`,`asid`) VALUES (?,?)") + stmts.notifyOne, err = db.Prepare("INSERT INTO `activity_stream_matches`(`watcher`,`asid`) VALUES (?,?)") if err != nil { return err } log.Print("Preparing addEmail statement.") - addEmailStmt, err = db.Prepare("INSERT INTO `emails`(`email`,`uid`,`validated`,`token`) VALUES (?,?,?,?)") + stmts.addEmail, err = db.Prepare("INSERT INTO `emails`(`email`,`uid`,`validated`,`token`) VALUES (?,?,?,?)") if err != nil { return err } log.Print("Preparing createProfileReply statement.") - createProfileReplyStmt, err = db.Prepare("INSERT INTO `users_replies`(`uid`,`content`,`parsed_content`,`createdAt`,`createdBy`,`ipaddress`) VALUES (?,?,?,UTC_TIMESTAMP(),?,?)") + stmts.createProfileReply, err = db.Prepare("INSERT INTO `users_replies`(`uid`,`content`,`parsed_content`,`createdAt`,`createdBy`,`ipaddress`) VALUES (?,?,?,UTC_TIMESTAMP(),?,?)") if err != nil { return err } log.Print("Preparing addSubscription statement.") - addSubscriptionStmt, err = db.Prepare("INSERT INTO `activity_subscriptions`(`user`,`targetID`,`targetType`,`level`) VALUES (?,?,?,2)") + stmts.addSubscription, err = db.Prepare("INSERT INTO `activity_subscriptions`(`user`,`targetID`,`targetType`,`level`) VALUES (?,?,?,2)") if err != nil { return err } log.Print("Preparing createForum statement.") - createForumStmt, err = db.Prepare("INSERT INTO `forums`(`name`,`desc`,`active`,`preset`) VALUES (?,?,?,?)") + stmts.createForum, err = db.Prepare("INSERT INTO `forums`(`name`,`desc`,`active`,`preset`) VALUES (?,?,?,?)") if err != nil { return err } log.Print("Preparing addForumPermsToForum statement.") - addForumPermsToForumStmt, err = db.Prepare("INSERT INTO `forums_permissions`(`gid`,`fid`,`preset`,`permissions`) VALUES (?,?,?,?)") + stmts.addForumPermsToForum, err = db.Prepare("INSERT INTO `forums_permissions`(`gid`,`fid`,`preset`,`permissions`) VALUES (?,?,?,?)") if err != nil { return err } log.Print("Preparing addPlugin statement.") - addPluginStmt, err = db.Prepare("INSERT INTO `plugins`(`uname`,`active`,`installed`) VALUES (?,?,?)") + stmts.addPlugin, err = db.Prepare("INSERT INTO `plugins`(`uname`,`active`,`installed`) VALUES (?,?,?)") if err != nil { return err } log.Print("Preparing addTheme statement.") - addThemeStmt, err = db.Prepare("INSERT INTO `themes`(`uname`,`default`) VALUES (?,?)") + stmts.addTheme, err = db.Prepare("INSERT INTO `themes`(`uname`,`default`) VALUES (?,?)") if err != nil { return err } log.Print("Preparing addModlogEntry statement.") - addModlogEntryStmt, err = db.Prepare("INSERT INTO `moderation_logs`(`action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt`) VALUES (?,?,?,?,?,UTC_TIMESTAMP())") + stmts.addModlogEntry, err = db.Prepare("INSERT INTO `moderation_logs`(`action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt`) VALUES (?,?,?,?,?,UTC_TIMESTAMP())") if err != nil { return err } log.Print("Preparing addAdminlogEntry statement.") - addAdminlogEntryStmt, err = db.Prepare("INSERT INTO `administration_logs`(`action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt`) VALUES (?,?,?,?,?,UTC_TIMESTAMP())") + stmts.addAdminlogEntry, err = db.Prepare("INSERT INTO `administration_logs`(`action`,`elementID`,`elementType`,`ipaddress`,`actorID`,`doneAt`) VALUES (?,?,?,?,?,UTC_TIMESTAMP())") if err != nil { return err } log.Print("Preparing addAttachment statement.") - addAttachmentStmt, err = db.Prepare("INSERT INTO `attachments`(`sectionID`,`sectionTable`,`originID`,`originTable`,`uploadedBy`,`path`) VALUES (?,?,?,?,?,?)") + stmts.addAttachment, err = db.Prepare("INSERT INTO `attachments`(`sectionID`,`sectionTable`,`originID`,`originTable`,`uploadedBy`,`path`) VALUES (?,?,?,?,?,?)") if err != nil { return err } log.Print("Preparing createWordFilter statement.") - createWordFilterStmt, err = db.Prepare("INSERT INTO `word_filters`(`find`,`replacement`) VALUES (?,?)") + stmts.createWordFilter, err = db.Prepare("INSERT INTO `word_filters`(`find`,`replacement`) VALUES (?,?)") if err != nil { return err } log.Print("Preparing addRepliesToTopic statement.") - addRepliesToTopicStmt, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` + ?,`lastReplyBy` = ?,`lastReplyAt` = UTC_TIMESTAMP() WHERE `tid` = ?") + stmts.addRepliesToTopic, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` + ?,`lastReplyBy` = ?,`lastReplyAt` = UTC_TIMESTAMP() WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing removeRepliesFromTopic statement.") - removeRepliesFromTopicStmt, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` - ? WHERE `tid` = ?") + stmts.removeRepliesFromTopic, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` - ? WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing addTopicsToForum statement.") - addTopicsToForumStmt, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` + ? WHERE `fid` = ?") + stmts.addTopicsToForum, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` + ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing removeTopicsFromForum statement.") - removeTopicsFromForumStmt, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` - ? WHERE `fid` = ?") + stmts.removeTopicsFromForum, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` - ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing updateForumCache statement.") - updateForumCacheStmt, err = db.Prepare("UPDATE `forums` SET `lastTopicID` = ?,`lastReplyerID` = ? WHERE `fid` = ?") + stmts.updateForumCache, err = db.Prepare("UPDATE `forums` SET `lastTopicID` = ?,`lastReplyerID` = ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing addLikesToTopic statement.") - addLikesToTopicStmt, err = db.Prepare("UPDATE `topics` SET `likeCount` = `likeCount` + ? WHERE `tid` = ?") + stmts.addLikesToTopic, err = db.Prepare("UPDATE `topics` SET `likeCount` = `likeCount` + ? WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing addLikesToReply statement.") - addLikesToReplyStmt, err = db.Prepare("UPDATE `replies` SET `likeCount` = `likeCount` + ? WHERE `rid` = ?") + stmts.addLikesToReply, err = db.Prepare("UPDATE `replies` SET `likeCount` = `likeCount` + ? WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing editTopic statement.") - editTopicStmt, err = db.Prepare("UPDATE `topics` SET `title` = ?,`content` = ?,`parsed_content` = ? WHERE `tid` = ?") + stmts.editTopic, err = db.Prepare("UPDATE `topics` SET `title` = ?,`content` = ?,`parsed_content` = ? WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing editReply statement.") - editReplyStmt, err = db.Prepare("UPDATE `replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") + stmts.editReply, err = db.Prepare("UPDATE `replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing stickTopic statement.") - stickTopicStmt, err = db.Prepare("UPDATE `topics` SET `sticky` = 1 WHERE `tid` = ?") + stmts.stickTopic, err = db.Prepare("UPDATE `topics` SET `sticky` = 1 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing unstickTopic statement.") - unstickTopicStmt, err = db.Prepare("UPDATE `topics` SET `sticky` = 0 WHERE `tid` = ?") + stmts.unstickTopic, err = db.Prepare("UPDATE `topics` SET `sticky` = 0 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing lockTopic statement.") - lockTopicStmt, err = db.Prepare("UPDATE `topics` SET `is_closed` = 1 WHERE `tid` = ?") + stmts.lockTopic, err = db.Prepare("UPDATE `topics` SET `is_closed` = 1 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing unlockTopic statement.") - unlockTopicStmt, err = db.Prepare("UPDATE `topics` SET `is_closed` = 0 WHERE `tid` = ?") + stmts.unlockTopic, err = db.Prepare("UPDATE `topics` SET `is_closed` = 0 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing updateLastIP statement.") - updateLastIPStmt, err = db.Prepare("UPDATE `users` SET `last_ip` = ? WHERE `uid` = ?") + stmts.updateLastIP, err = db.Prepare("UPDATE `users` SET `last_ip` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateSession statement.") - updateSessionStmt, err = db.Prepare("UPDATE `users` SET `session` = ? WHERE `uid` = ?") + stmts.updateSession, err = db.Prepare("UPDATE `users` SET `session` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing setPassword statement.") - setPasswordStmt, err = db.Prepare("UPDATE `users` SET `password` = ?,`salt` = ? WHERE `uid` = ?") + stmts.setPassword, err = db.Prepare("UPDATE `users` SET `password` = ?,`salt` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing setAvatar statement.") - setAvatarStmt, err = db.Prepare("UPDATE `users` SET `avatar` = ? WHERE `uid` = ?") + stmts.setAvatar, err = db.Prepare("UPDATE `users` SET `avatar` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing setUsername statement.") - setUsernameStmt, err = db.Prepare("UPDATE `users` SET `name` = ? WHERE `uid` = ?") + stmts.setUsername, err = db.Prepare("UPDATE `users` SET `name` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing changeGroup statement.") - changeGroupStmt, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") + stmts.changeGroup, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing activateUser statement.") - activateUserStmt, err = db.Prepare("UPDATE `users` SET `active` = 1 WHERE `uid` = ?") + stmts.activateUser, err = db.Prepare("UPDATE `users` SET `active` = 1 WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateUserLevel statement.") - updateUserLevelStmt, err = db.Prepare("UPDATE `users` SET `level` = ? WHERE `uid` = ?") + stmts.updateUserLevel, err = db.Prepare("UPDATE `users` SET `level` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserScore statement.") - incrementUserScoreStmt, err = db.Prepare("UPDATE `users` SET `score` = `score` + ? WHERE `uid` = ?") + stmts.incrementUserScore, err = db.Prepare("UPDATE `users` SET `score` = `score` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserPosts statement.") - incrementUserPostsStmt, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ? WHERE `uid` = ?") + stmts.incrementUserPosts, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserBigposts statement.") - incrementUserBigpostsStmt, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ? WHERE `uid` = ?") + stmts.incrementUserBigposts, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserMegaposts statement.") - incrementUserMegapostsStmt, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ?,`megaposts` = `megaposts` + ? WHERE `uid` = ?") + stmts.incrementUserMegaposts, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ?,`megaposts` = `megaposts` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserTopics statement.") - incrementUserTopicsStmt, err = db.Prepare("UPDATE `users` SET `topics` = `topics` + ? WHERE `uid` = ?") + stmts.incrementUserTopics, err = db.Prepare("UPDATE `users` SET `topics` = `topics` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing editProfileReply statement.") - editProfileReplyStmt, err = db.Prepare("UPDATE `users_replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") + stmts.editProfileReply, err = db.Prepare("UPDATE `users_replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing updateForum statement.") - updateForumStmt, err = db.Prepare("UPDATE `forums` SET `name` = ?,`desc` = ?,`active` = ?,`preset` = ? WHERE `fid` = ?") + stmts.updateForum, err = db.Prepare("UPDATE `forums` SET `name` = ?,`desc` = ?,`active` = ?,`preset` = ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing updateSetting statement.") - updateSettingStmt, err = db.Prepare("UPDATE `settings` SET `content` = ? WHERE `name` = ?") + stmts.updateSetting, err = db.Prepare("UPDATE `settings` SET `content` = ? WHERE `name` = ?") if err != nil { return err } log.Print("Preparing updatePlugin statement.") - updatePluginStmt, err = db.Prepare("UPDATE `plugins` SET `active` = ? WHERE `uname` = ?") + stmts.updatePlugin, err = db.Prepare("UPDATE `plugins` SET `active` = ? WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing updatePluginInstall statement.") - updatePluginInstallStmt, err = db.Prepare("UPDATE `plugins` SET `installed` = ? WHERE `uname` = ?") + stmts.updatePluginInstall, err = db.Prepare("UPDATE `plugins` SET `installed` = ? WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing updateTheme statement.") - updateThemeStmt, err = db.Prepare("UPDATE `themes` SET `default` = ? WHERE `uname` = ?") + stmts.updateTheme, err = db.Prepare("UPDATE `themes` SET `default` = ? WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing updateUser statement.") - updateUserStmt, err = db.Prepare("UPDATE `users` SET `name` = ?,`email` = ?,`group` = ? WHERE `uid` = ?") + stmts.updateUser, err = db.Prepare("UPDATE `users` SET `name` = ?,`email` = ?,`group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateUserGroup statement.") - updateUserGroupStmt, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") + stmts.updateUserGroup, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateGroupPerms statement.") - updateGroupPermsStmt, err = db.Prepare("UPDATE `users_groups` SET `permissions` = ? WHERE `gid` = ?") + stmts.updateGroupPerms, err = db.Prepare("UPDATE `users_groups` SET `permissions` = ? WHERE `gid` = ?") if err != nil { return err } log.Print("Preparing updateGroupRank statement.") - updateGroupRankStmt, err = db.Prepare("UPDATE `users_groups` SET `is_admin` = ?,`is_mod` = ?,`is_banned` = ? WHERE `gid` = ?") + stmts.updateGroupRank, err = db.Prepare("UPDATE `users_groups` SET `is_admin` = ?,`is_mod` = ?,`is_banned` = ? WHERE `gid` = ?") if err != nil { return err } log.Print("Preparing updateGroup statement.") - updateGroupStmt, err = db.Prepare("UPDATE `users_groups` SET `name` = ?,`tag` = ? WHERE `gid` = ?") + stmts.updateGroup, err = db.Prepare("UPDATE `users_groups` SET `name` = ?,`tag` = ? WHERE `gid` = ?") if err != nil { return err } log.Print("Preparing updateEmail statement.") - updateEmailStmt, err = db.Prepare("UPDATE `emails` SET `email` = ?,`uid` = ?,`validated` = ?,`token` = ? WHERE `email` = ?") + stmts.updateEmail, err = db.Prepare("UPDATE `emails` SET `email` = ?,`uid` = ?,`validated` = ?,`token` = ? WHERE `email` = ?") if err != nil { return err } log.Print("Preparing verifyEmail statement.") - verifyEmailStmt, err = db.Prepare("UPDATE `emails` SET `validated` = 1,`token` = '' WHERE `email` = ?") + stmts.verifyEmail, err = db.Prepare("UPDATE `emails` SET `validated` = 1,`token` = '' WHERE `email` = ?") if err != nil { return err } log.Print("Preparing setTempGroup statement.") - setTempGroupStmt, err = db.Prepare("UPDATE `users` SET `temp_group` = ? WHERE `uid` = ?") + stmts.setTempGroup, err = db.Prepare("UPDATE `users` SET `temp_group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateWordFilter statement.") - updateWordFilterStmt, err = db.Prepare("UPDATE `word_filters` SET `find` = ?,`replacement` = ? WHERE `wfid` = ?") + stmts.updateWordFilter, err = db.Prepare("UPDATE `word_filters` SET `find` = ?,`replacement` = ? WHERE `wfid` = ?") if err != nil { return err } log.Print("Preparing bumpSync statement.") - bumpSyncStmt, err = db.Prepare("UPDATE `sync` SET `last_update` = UTC_TIMESTAMP()") + stmts.bumpSync, err = db.Prepare("UPDATE `sync` SET `last_update` = UTC_TIMESTAMP()") if err != nil { return err } log.Print("Preparing deleteUser statement.") - deleteUserStmt, err = db.Prepare("DELETE FROM `users` WHERE `uid` = ?") + stmts.deleteUser, err = db.Prepare("DELETE FROM `users` WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing deleteTopic statement.") - deleteTopicStmt, err = db.Prepare("DELETE FROM `topics` WHERE `tid` = ?") + stmts.deleteTopic, err = db.Prepare("DELETE FROM `topics` WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing deleteReply statement.") - deleteReplyStmt, err = db.Prepare("DELETE FROM `replies` WHERE `rid` = ?") + stmts.deleteReply, err = db.Prepare("DELETE FROM `replies` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing deleteProfileReply statement.") - deleteProfileReplyStmt, err = db.Prepare("DELETE FROM `users_replies` WHERE `rid` = ?") + stmts.deleteProfileReply, err = db.Prepare("DELETE FROM `users_replies` WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing deleteActivityStreamMatch statement.") - deleteActivityStreamMatchStmt, err = db.Prepare("DELETE FROM `activity_stream_matches` WHERE `watcher` = ? AND `asid` = ?") + stmts.deleteActivityStreamMatch, err = db.Prepare("DELETE FROM `activity_stream_matches` WHERE `watcher` = ? AND `asid` = ?") if err != nil { return err } log.Print("Preparing deleteWordFilter statement.") - deleteWordFilterStmt, err = db.Prepare("DELETE FROM `word_filters` WHERE `wfid` = ?") + stmts.deleteWordFilter, err = db.Prepare("DELETE FROM `word_filters` WHERE `wfid` = ?") if err != nil { return err } log.Print("Preparing reportExists statement.") - reportExistsStmt, err = db.Prepare("SELECT COUNT(*) AS `count` FROM `topics` WHERE `data` = ? AND `data` != '' AND `parentID` = 1") + stmts.reportExists, err = db.Prepare("SELECT COUNT(*) AS `count` FROM `topics` WHERE `data` = ? AND `data` != '' AND `parentID` = 1") if err != nil { return err } log.Print("Preparing groupCount statement.") - groupCountStmt, err = db.Prepare("SELECT COUNT(*) AS `count` FROM `users_groups`") + stmts.groupCount, err = db.Prepare("SELECT COUNT(*) AS `count` FROM `users_groups`") if err != nil { return err } log.Print("Preparing modlogCount statement.") - modlogCountStmt, err = db.Prepare("SELECT COUNT(*) AS `count` FROM `moderation_logs`") + stmts.modlogCount, err = db.Prepare("SELECT COUNT(*) AS `count` FROM `moderation_logs`") if err != nil { return err } log.Print("Preparing notifyWatchers statement.") - notifyWatchersStmt, err = db.Prepare("INSERT INTO `activity_stream_matches`(`watcher`,`asid`) SELECT `activity_subscriptions`.`user`, `activity_stream`.`asid` FROM `activity_stream` INNER JOIN `activity_subscriptions` ON `activity_subscriptions`.`targetType` = `activity_stream`.`elementType` AND `activity_subscriptions`.`targetID` = `activity_stream`.`elementID` AND `activity_subscriptions`.`user` != `activity_stream`.`actor` WHERE `asid` = ?") + stmts.notifyWatchers, err = db.Prepare("INSERT INTO `activity_stream_matches`(`watcher`,`asid`) SELECT `activity_subscriptions`.`user`, `activity_stream`.`asid` FROM `activity_stream` INNER JOIN `activity_subscriptions` ON `activity_subscriptions`.`targetType` = `activity_stream`.`elementType` AND `activity_subscriptions`.`targetID` = `activity_stream`.`elementID` AND `activity_subscriptions`.`user` != `activity_stream`.`actor` WHERE `asid` = ?") if err != nil { return err } diff --git a/gen_pgsql.go b/gen_pgsql.go index b4b33281..74913f9c 100644 --- a/gen_pgsql.go +++ b/gen_pgsql.go @@ -7,48 +7,62 @@ import "log" import "database/sql" // nolint -var addRepliesToTopicStmt *sql.Stmt -var removeRepliesFromTopicStmt *sql.Stmt -var addTopicsToForumStmt *sql.Stmt -var removeTopicsFromForumStmt *sql.Stmt -var updateForumCacheStmt *sql.Stmt -var addLikesToTopicStmt *sql.Stmt -var addLikesToReplyStmt *sql.Stmt -var editTopicStmt *sql.Stmt -var editReplyStmt *sql.Stmt -var stickTopicStmt *sql.Stmt -var unstickTopicStmt *sql.Stmt -var lockTopicStmt *sql.Stmt -var unlockTopicStmt *sql.Stmt -var updateLastIPStmt *sql.Stmt -var updateSessionStmt *sql.Stmt -var setPasswordStmt *sql.Stmt -var setAvatarStmt *sql.Stmt -var setUsernameStmt *sql.Stmt -var changeGroupStmt *sql.Stmt -var activateUserStmt *sql.Stmt -var updateUserLevelStmt *sql.Stmt -var incrementUserScoreStmt *sql.Stmt -var incrementUserPostsStmt *sql.Stmt -var incrementUserBigpostsStmt *sql.Stmt -var incrementUserMegapostsStmt *sql.Stmt -var incrementUserTopicsStmt *sql.Stmt -var editProfileReplyStmt *sql.Stmt -var updateForumStmt *sql.Stmt -var updateSettingStmt *sql.Stmt -var updatePluginStmt *sql.Stmt -var updatePluginInstallStmt *sql.Stmt -var updateThemeStmt *sql.Stmt -var updateUserStmt *sql.Stmt -var updateUserGroupStmt *sql.Stmt -var updateGroupPermsStmt *sql.Stmt -var updateGroupRankStmt *sql.Stmt -var updateGroupStmt *sql.Stmt -var updateEmailStmt *sql.Stmt -var verifyEmailStmt *sql.Stmt -var setTempGroupStmt *sql.Stmt -var updateWordFilterStmt *sql.Stmt -var bumpSyncStmt *sql.Stmt +type Stmts struct { + addRepliesToTopic *sql.Stmt + removeRepliesFromTopic *sql.Stmt + addTopicsToForum *sql.Stmt + removeTopicsFromForum *sql.Stmt + updateForumCache *sql.Stmt + addLikesToTopic *sql.Stmt + addLikesToReply *sql.Stmt + editTopic *sql.Stmt + editReply *sql.Stmt + stickTopic *sql.Stmt + unstickTopic *sql.Stmt + lockTopic *sql.Stmt + unlockTopic *sql.Stmt + updateLastIP *sql.Stmt + updateSession *sql.Stmt + setPassword *sql.Stmt + setAvatar *sql.Stmt + setUsername *sql.Stmt + changeGroup *sql.Stmt + activateUser *sql.Stmt + updateUserLevel *sql.Stmt + incrementUserScore *sql.Stmt + incrementUserPosts *sql.Stmt + incrementUserBigposts *sql.Stmt + incrementUserMegaposts *sql.Stmt + incrementUserTopics *sql.Stmt + editProfileReply *sql.Stmt + updateForum *sql.Stmt + updateSetting *sql.Stmt + updatePlugin *sql.Stmt + updatePluginInstall *sql.Stmt + updateTheme *sql.Stmt + updateUser *sql.Stmt + updateUserGroup *sql.Stmt + updateGroupPerms *sql.Stmt + updateGroupRank *sql.Stmt + updateGroup *sql.Stmt + updateEmail *sql.Stmt + verifyEmail *sql.Stmt + setTempGroup *sql.Stmt + updateWordFilter *sql.Stmt + bumpSync *sql.Stmt + + getActivityFeedByWatcher *sql.Stmt + getActivityCountByWatcher *sql.Stmt + todaysPostCount *sql.Stmt + todaysTopicCount *sql.Stmt + todaysReportCount *sql.Stmt + todaysNewUserCount *sql.Stmt + findUsersByIPUsers *sql.Stmt + findUsersByIPTopics *sql.Stmt + findUsersByIPReplies *sql.Stmt + + Mocks bool +} // nolint func _gen_pgsql() (err error) { @@ -57,253 +71,253 @@ func _gen_pgsql() (err error) { } log.Print("Preparing addRepliesToTopic statement.") - addRepliesToTopicStmt, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` + ?,`lastReplyBy` = ?,`lastReplyAt` = LOCALTIMESTAMP() WHERE `tid` = ?") + stmts.addRepliesToTopic, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` + ?,`lastReplyBy` = ?,`lastReplyAt` = LOCALTIMESTAMP() WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing removeRepliesFromTopic statement.") - removeRepliesFromTopicStmt, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` - ? WHERE `tid` = ?") + stmts.removeRepliesFromTopic, err = db.Prepare("UPDATE `topics` SET `postCount` = `postCount` - ? WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing addTopicsToForum statement.") - addTopicsToForumStmt, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` + ? WHERE `fid` = ?") + stmts.addTopicsToForum, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` + ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing removeTopicsFromForum statement.") - removeTopicsFromForumStmt, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` - ? WHERE `fid` = ?") + stmts.removeTopicsFromForum, err = db.Prepare("UPDATE `forums` SET `topicCount` = `topicCount` - ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing updateForumCache statement.") - updateForumCacheStmt, err = db.Prepare("UPDATE `forums` SET `lastTopicID` = ?,`lastReplyerID` = ? WHERE `fid` = ?") + stmts.updateForumCache, err = db.Prepare("UPDATE `forums` SET `lastTopicID` = ?,`lastReplyerID` = ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing addLikesToTopic statement.") - addLikesToTopicStmt, err = db.Prepare("UPDATE `topics` SET `likeCount` = `likeCount` + ? WHERE `tid` = ?") + stmts.addLikesToTopic, err = db.Prepare("UPDATE `topics` SET `likeCount` = `likeCount` + ? WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing addLikesToReply statement.") - addLikesToReplyStmt, err = db.Prepare("UPDATE `replies` SET `likeCount` = `likeCount` + ? WHERE `rid` = ?") + stmts.addLikesToReply, err = db.Prepare("UPDATE `replies` SET `likeCount` = `likeCount` + ? WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing editTopic statement.") - editTopicStmt, err = db.Prepare("UPDATE `topics` SET `title` = ?,`content` = ?,`parsed_content` = ? WHERE `tid` = ?") + stmts.editTopic, err = db.Prepare("UPDATE `topics` SET `title` = ?,`content` = ?,`parsed_content` = ? WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing editReply statement.") - editReplyStmt, err = db.Prepare("UPDATE `replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") + stmts.editReply, err = db.Prepare("UPDATE `replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing stickTopic statement.") - stickTopicStmt, err = db.Prepare("UPDATE `topics` SET `sticky` = 1 WHERE `tid` = ?") + stmts.stickTopic, err = db.Prepare("UPDATE `topics` SET `sticky` = 1 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing unstickTopic statement.") - unstickTopicStmt, err = db.Prepare("UPDATE `topics` SET `sticky` = 0 WHERE `tid` = ?") + stmts.unstickTopic, err = db.Prepare("UPDATE `topics` SET `sticky` = 0 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing lockTopic statement.") - lockTopicStmt, err = db.Prepare("UPDATE `topics` SET `is_closed` = 1 WHERE `tid` = ?") + stmts.lockTopic, err = db.Prepare("UPDATE `topics` SET `is_closed` = 1 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing unlockTopic statement.") - unlockTopicStmt, err = db.Prepare("UPDATE `topics` SET `is_closed` = 0 WHERE `tid` = ?") + stmts.unlockTopic, err = db.Prepare("UPDATE `topics` SET `is_closed` = 0 WHERE `tid` = ?") if err != nil { return err } log.Print("Preparing updateLastIP statement.") - updateLastIPStmt, err = db.Prepare("UPDATE `users` SET `last_ip` = ? WHERE `uid` = ?") + stmts.updateLastIP, err = db.Prepare("UPDATE `users` SET `last_ip` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateSession statement.") - updateSessionStmt, err = db.Prepare("UPDATE `users` SET `session` = ? WHERE `uid` = ?") + stmts.updateSession, err = db.Prepare("UPDATE `users` SET `session` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing setPassword statement.") - setPasswordStmt, err = db.Prepare("UPDATE `users` SET `password` = ?,`salt` = ? WHERE `uid` = ?") + stmts.setPassword, err = db.Prepare("UPDATE `users` SET `password` = ?,`salt` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing setAvatar statement.") - setAvatarStmt, err = db.Prepare("UPDATE `users` SET `avatar` = ? WHERE `uid` = ?") + stmts.setAvatar, err = db.Prepare("UPDATE `users` SET `avatar` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing setUsername statement.") - setUsernameStmt, err = db.Prepare("UPDATE `users` SET `name` = ? WHERE `uid` = ?") + stmts.setUsername, err = db.Prepare("UPDATE `users` SET `name` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing changeGroup statement.") - changeGroupStmt, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") + stmts.changeGroup, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing activateUser statement.") - activateUserStmt, err = db.Prepare("UPDATE `users` SET `active` = 1 WHERE `uid` = ?") + stmts.activateUser, err = db.Prepare("UPDATE `users` SET `active` = 1 WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateUserLevel statement.") - updateUserLevelStmt, err = db.Prepare("UPDATE `users` SET `level` = ? WHERE `uid` = ?") + stmts.updateUserLevel, err = db.Prepare("UPDATE `users` SET `level` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserScore statement.") - incrementUserScoreStmt, err = db.Prepare("UPDATE `users` SET `score` = `score` + ? WHERE `uid` = ?") + stmts.incrementUserScore, err = db.Prepare("UPDATE `users` SET `score` = `score` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserPosts statement.") - incrementUserPostsStmt, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ? WHERE `uid` = ?") + stmts.incrementUserPosts, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserBigposts statement.") - incrementUserBigpostsStmt, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ? WHERE `uid` = ?") + stmts.incrementUserBigposts, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserMegaposts statement.") - incrementUserMegapostsStmt, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ?,`megaposts` = `megaposts` + ? WHERE `uid` = ?") + stmts.incrementUserMegaposts, err = db.Prepare("UPDATE `users` SET `posts` = `posts` + ?,`bigposts` = `bigposts` + ?,`megaposts` = `megaposts` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing incrementUserTopics statement.") - incrementUserTopicsStmt, err = db.Prepare("UPDATE `users` SET `topics` = `topics` + ? WHERE `uid` = ?") + stmts.incrementUserTopics, err = db.Prepare("UPDATE `users` SET `topics` = `topics` + ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing editProfileReply statement.") - editProfileReplyStmt, err = db.Prepare("UPDATE `users_replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") + stmts.editProfileReply, err = db.Prepare("UPDATE `users_replies` SET `content` = ?,`parsed_content` = ? WHERE `rid` = ?") if err != nil { return err } log.Print("Preparing updateForum statement.") - updateForumStmt, err = db.Prepare("UPDATE `forums` SET `name` = ?,`desc` = ?,`active` = ?,`preset` = ? WHERE `fid` = ?") + stmts.updateForum, err = db.Prepare("UPDATE `forums` SET `name` = ?,`desc` = ?,`active` = ?,`preset` = ? WHERE `fid` = ?") if err != nil { return err } log.Print("Preparing updateSetting statement.") - updateSettingStmt, err = db.Prepare("UPDATE `settings` SET `content` = ? WHERE `name` = ?") + stmts.updateSetting, err = db.Prepare("UPDATE `settings` SET `content` = ? WHERE `name` = ?") if err != nil { return err } log.Print("Preparing updatePlugin statement.") - updatePluginStmt, err = db.Prepare("UPDATE `plugins` SET `active` = ? WHERE `uname` = ?") + stmts.updatePlugin, err = db.Prepare("UPDATE `plugins` SET `active` = ? WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing updatePluginInstall statement.") - updatePluginInstallStmt, err = db.Prepare("UPDATE `plugins` SET `installed` = ? WHERE `uname` = ?") + stmts.updatePluginInstall, err = db.Prepare("UPDATE `plugins` SET `installed` = ? WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing updateTheme statement.") - updateThemeStmt, err = db.Prepare("UPDATE `themes` SET `default` = ? WHERE `uname` = ?") + stmts.updateTheme, err = db.Prepare("UPDATE `themes` SET `default` = ? WHERE `uname` = ?") if err != nil { return err } log.Print("Preparing updateUser statement.") - updateUserStmt, err = db.Prepare("UPDATE `users` SET `name` = ?,`email` = ?,`group` = ? WHERE `uid` = ?") + stmts.updateUser, err = db.Prepare("UPDATE `users` SET `name` = ?,`email` = ?,`group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateUserGroup statement.") - updateUserGroupStmt, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") + stmts.updateUserGroup, err = db.Prepare("UPDATE `users` SET `group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateGroupPerms statement.") - updateGroupPermsStmt, err = db.Prepare("UPDATE `users_groups` SET `permissions` = ? WHERE `gid` = ?") + stmts.updateGroupPerms, err = db.Prepare("UPDATE `users_groups` SET `permissions` = ? WHERE `gid` = ?") if err != nil { return err } log.Print("Preparing updateGroupRank statement.") - updateGroupRankStmt, err = db.Prepare("UPDATE `users_groups` SET `is_admin` = ?,`is_mod` = ?,`is_banned` = ? WHERE `gid` = ?") + stmts.updateGroupRank, err = db.Prepare("UPDATE `users_groups` SET `is_admin` = ?,`is_mod` = ?,`is_banned` = ? WHERE `gid` = ?") if err != nil { return err } log.Print("Preparing updateGroup statement.") - updateGroupStmt, err = db.Prepare("UPDATE `users_groups` SET `name` = ?,`tag` = ? WHERE `gid` = ?") + stmts.updateGroup, err = db.Prepare("UPDATE `users_groups` SET `name` = ?,`tag` = ? WHERE `gid` = ?") if err != nil { return err } log.Print("Preparing updateEmail statement.") - updateEmailStmt, err = db.Prepare("UPDATE `emails` SET `email` = ?,`uid` = ?,`validated` = ?,`token` = ? WHERE `email` = ?") + stmts.updateEmail, err = db.Prepare("UPDATE `emails` SET `email` = ?,`uid` = ?,`validated` = ?,`token` = ? WHERE `email` = ?") if err != nil { return err } log.Print("Preparing verifyEmail statement.") - verifyEmailStmt, err = db.Prepare("UPDATE `emails` SET `validated` = 1,`token` = '' WHERE `email` = ?") + stmts.verifyEmail, err = db.Prepare("UPDATE `emails` SET `validated` = 1,`token` = '' WHERE `email` = ?") if err != nil { return err } log.Print("Preparing setTempGroup statement.") - setTempGroupStmt, err = db.Prepare("UPDATE `users` SET `temp_group` = ? WHERE `uid` = ?") + stmts.setTempGroup, err = db.Prepare("UPDATE `users` SET `temp_group` = ? WHERE `uid` = ?") if err != nil { return err } log.Print("Preparing updateWordFilter statement.") - updateWordFilterStmt, err = db.Prepare("UPDATE `word_filters` SET `find` = ?,`replacement` = ? WHERE `wfid` = ?") + stmts.updateWordFilter, err = db.Prepare("UPDATE `word_filters` SET `find` = ?,`replacement` = ? WHERE `wfid` = ?") if err != nil { return err } log.Print("Preparing bumpSync statement.") - bumpSyncStmt, err = db.Prepare("UPDATE `sync` SET `last_update` = LOCALTIMESTAMP()") + stmts.bumpSync, err = db.Prepare("UPDATE `sync` SET `last_update` = LOCALTIMESTAMP()") if err != nil { return err } diff --git a/gen_router.go b/gen_router.go index ac394f7f..d3e27aff 100644 --- a/gen_router.go +++ b/gen_router.go @@ -136,6 +136,12 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { router.handleError(err,w,req,user) } case "/report": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + switch(req.URL.Path) { case "/report/submit/": err = routeReportSubmit(w,req,user,extra_data) @@ -146,6 +152,12 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { case "/topics": switch(req.URL.Path) { case "/topics/create/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + err = routeTopicCreate(w,req,user,extra_data) default: err = routeTopics(w,req,user) @@ -233,6 +245,79 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { if err != nil { router.handleError(err,w,req,user) } + case "/user": + switch(req.URL.Path) { + case "/user/edit/critical/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditCritical(w,req,user) + case "/user/edit/critical/submit/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditCriticalSubmit(w,req,user) + case "/user/edit/avatar/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditAvatar(w,req,user) + case "/user/edit/avatar/submit/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditAvatarSubmit(w,req,user) + case "/user/edit/username/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditUsername(w,req,user) + case "/user/edit/username/submit/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditUsernameSubmit(w,req,user) + case "/user/edit/email/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditEmail(w,req,user) + case "/user/edit/token/": + err = MemberOnly(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + + err = routeAccountOwnEditEmailTokenSubmit(w,req,user,extra_data) + default: + req.URL.Path += extra_data + err = routeProfile(w,req,user) + } + if err != nil { + router.handleError(err,w,req,user) + } case "/uploads": if extra_data == "" { NotFound(w,req) diff --git a/group.go b/group.go index a138e5d8..88712c82 100644 --- a/group.go +++ b/group.go @@ -28,7 +28,7 @@ type Group struct { } func (group *Group) ChangeRank(isAdmin bool, isMod bool, isBanned bool) (err error) { - _, err = updateGroupRankStmt.Exec(isAdmin, isMod, isBanned, group.ID) + _, err = stmts.updateGroupRank.Exec(isAdmin, isMod, isBanned, group.ID) if err != nil { return err } diff --git a/group_store.go b/group_store.go index 4cb5ea6a..0efa3344 100644 --- a/group_store.go +++ b/group_store.go @@ -54,12 +54,13 @@ func NewMemoryGroupStore() (*MemoryGroupStore, error) { }, nil } +// TODO: Move this query from the global stmt store into this store func (mgs *MemoryGroupStore) LoadGroups() error { mgs.Lock() defer mgs.Unlock() mgs.groups[0] = &Group{ID: 0, Name: "Unknown"} - rows, err := getGroupsStmt.Query() + rows, err := stmts.getGroups.Query() if err != nil { return err } diff --git a/main.go b/main.go index b7af5be8..5175ab34 100644 --- a/main.go +++ b/main.go @@ -75,6 +75,13 @@ func (slice StringList) Contains(needle string) bool { var staticFiles = make(map[string]SFile) var logWriter = io.MultiWriter(os.Stderr) +// TODO: Wrap the globals in here so we can pass pointers to them to subpackages +var globs *Globs + +type Globs struct { + stmts *Stmts +} + func main() { // TODO: Recover from panics /*defer func() { @@ -238,18 +245,21 @@ func main() { //router.HandleFunc("/accounts/list/", routeLogin) // Redirect /accounts/ and /user/ to here.. // Get a list of all of the accounts on the forum //router.HandleFunc("/accounts/create/full/", routeLogout) // Advanced account creator for admins? //router.HandleFunc("/user/edit/", routeLogout) - router.HandleFunc("/user/edit/critical/", routeAccountOwnEditCritical) // Password & Email - router.HandleFunc("/user/edit/critical/submit/", routeAccountOwnEditCriticalSubmit) - router.HandleFunc("/user/edit/avatar/", routeAccountOwnEditAvatar) - router.HandleFunc("/user/edit/avatar/submit/", routeAccountOwnEditAvatarSubmit) - router.HandleFunc("/user/edit/username/", routeAccountOwnEditUsername) - router.HandleFunc("/user/edit/username/submit/", routeAccountOwnEditUsernameSubmit) - router.HandleFunc("/user/edit/email/", routeAccountOwnEditEmail) - router.HandleFunc("/user/edit/token/", routeAccountOwnEditEmailTokenSubmit) - router.HandleFunc("/user/", routeProfile) + ////router.HandleFunc("/user/edit/critical/", routeAccountOwnEditCritical) // Password & Email + ////router.HandleFunc("/user/edit/critical/submit/", routeAccountOwnEditCriticalSubmit) + ////router.HandleFunc("/user/edit/avatar/", routeAccountOwnEditAvatar) + ////router.HandleFunc("/user/edit/avatar/submit/", routeAccountOwnEditAvatarSubmit) + ////router.HandleFunc("/user/edit/username/", routeAccountOwnEditUsername) + ////router.HandleFunc("/user/edit/username/submit/", routeAccountOwnEditUsernameSubmit) + ////router.HandleFunc("/user/edit/email/", routeAccountOwnEditEmail) + ////router.HandleFunc("/user/edit/token/", routeAccountOwnEditEmailTokenSubmit) + ////router.HandleFunc("/user/", routeProfile) + + // TODO: Move these into /user/? router.HandleFunc("/profile/reply/create/", routeProfileReplyCreate) router.HandleFunc("/profile/reply/edit/submit/", routeProfileReplyEditSubmit) router.HandleFunc("/profile/reply/delete/submit/", routeProfileReplyDeleteSubmit) + //router.HandleFunc("/user/edit/submit/", routeLogout) // routeLogout? what on earth? o.o //router.HandleFunc("/users/ban/", routeBan) router.HandleFunc("/users/ban/submit/", routeBanSubmit) diff --git a/member_routes.go b/member_routes.go index 8dc93567..b3278858 100644 --- a/member_routes.go +++ b/member_routes.go @@ -153,7 +153,7 @@ func routeTopicCreateSubmit(w http.ResponseWriter, r *http.Request, user User) R } } - _, err = addSubscriptionStmt.Exec(user.ID, tid, "topic") + _, err = stmts.addSubscription.Exec(user.ID, tid, "topic") if err != nil { return InternalError(err, w, r) } @@ -224,7 +224,7 @@ func routeTopicCreateSubmit(w http.ResponseWriter, r *http.Request, user User) R return LocalError("Upload failed [Copy Failed]", w, r, user) } - _, err = addAttachmentStmt.Exec(fid, "forums", tid, "topics", user.ID, filename) + _, err = stmts.addAttachment.Exec(fid, "forums", tid, "topics", user.ID, filename) if err != nil { return InternalError(err, w, r) } @@ -329,7 +329,7 @@ func routeCreateReply(w http.ResponseWriter, r *http.Request, user User) RouteEr return LocalError("Upload failed [Copy Failed]", w, r, user) } - _, err = addAttachmentStmt.Exec(topic.ParentID, "forums", tid, "replies", user.ID, filename) + _, err = stmts.addAttachment.Exec(topic.ParentID, "forums", tid, "replies", user.ID, filename) if err != nil { return InternalError(err, w, r) } @@ -353,7 +353,7 @@ func routeCreateReply(w http.ResponseWriter, r *http.Request, user User) RouteEr return InternalError(err, w, r) } - res, err := addActivityStmt.Exec(user.ID, topic.CreatedBy, "reply", "topic", tid) + res, err := stmts.addActivity.Exec(user.ID, topic.CreatedBy, "reply", "topic", tid) if err != nil { return InternalError(err, w, r) } @@ -362,7 +362,7 @@ func routeCreateReply(w http.ResponseWriter, r *http.Request, user User) RouteEr return InternalError(err, w, r) } - _, err = notifyWatchersStmt.Exec(lastID) + _, err = stmts.notifyWatchers.Exec(lastID) if err != nil { return InternalError(err, w, r) } @@ -414,7 +414,7 @@ func routeLikeTopic(w http.ResponseWriter, r *http.Request, user User) RouteErro return LocalError("You can't like your own topics", w, r, user) } - err = hasLikedTopicStmt.QueryRow(user.ID, tid).Scan(&tid) + err = stmts.hasLikedTopic.QueryRow(user.ID, tid).Scan(&tid) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } else if err != ErrNoRows { @@ -429,17 +429,17 @@ func routeLikeTopic(w http.ResponseWriter, r *http.Request, user User) RouteErro } score := 1 - _, err = createLikeStmt.Exec(score, tid, "topics", user.ID) + _, err = stmts.createLike.Exec(score, tid, "topics", user.ID) if err != nil { return InternalError(err, w, r) } - _, err = addLikesToTopicStmt.Exec(1, tid) + _, err = stmts.addLikesToTopic.Exec(1, tid) if err != nil { return InternalError(err, w, r) } - res, err := addActivityStmt.Exec(user.ID, topic.CreatedBy, "like", "topic", tid) + res, err := stmts.addActivity.Exec(user.ID, topic.CreatedBy, "like", "topic", tid) if err != nil { return InternalError(err, w, r) } @@ -448,7 +448,7 @@ func routeLikeTopic(w http.ResponseWriter, r *http.Request, user User) RouteErro return InternalError(err, w, r) } - _, err = notifyOneStmt.Exec(topic.CreatedBy, lastID) + _, err = stmts.notifyOne.Exec(topic.CreatedBy, lastID) if err != nil { return InternalError(err, w, r) } @@ -484,7 +484,7 @@ func routeReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user User) Rou } var fid int - err = getTopicFIDStmt.QueryRow(reply.ParentID).Scan(&fid) + err = stmts.getTopicFID.QueryRow(reply.ParentID).Scan(&fid) if err == ErrNoRows { return PreError("The parent topic doesn't exist.", w, r) } else if err != nil { @@ -518,7 +518,7 @@ func routeReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user User) Rou return InternalError(err, w, r) } - res, err := addActivityStmt.Exec(user.ID, reply.CreatedBy, "like", "post", rid) + res, err := stmts.addActivity.Exec(user.ID, reply.CreatedBy, "like", "post", rid) if err != nil { return InternalError(err, w, r) } @@ -527,7 +527,7 @@ func routeReplyLikeSubmit(w http.ResponseWriter, r *http.Request, user User) Rou return InternalError(err, w, r) } - _, err = notifyOneStmt.Exec(reply.CreatedBy, lastID) + _, err = stmts.notifyOne.Exec(reply.CreatedBy, lastID) if err != nil { return InternalError(err, w, r) } @@ -559,13 +559,13 @@ func routeProfileReplyCreate(w http.ResponseWriter, r *http.Request, user User) } content := html.EscapeString(preparseMessage(r.PostFormValue("reply-content"))) - _, err = createProfileReplyStmt.Exec(uid, content, parseMessage(content, 0, ""), user.ID, ipaddress) + _, err = stmts.createProfileReply.Exec(uid, content, parseMessage(content, 0, ""), user.ID, ipaddress) if err != nil { return InternalError(err, w, r) } var userName string - err = getUserNameStmt.QueryRow(uid).Scan(&userName) + err = stmts.getUserName.QueryRow(uid).Scan(&userName) if err == ErrNoRows { return LocalError("The profile you're trying to post on doesn't exist.", w, r, user) } else if err != nil { @@ -626,7 +626,7 @@ func routeReportSubmit(w http.ResponseWriter, r *http.Request, user User, sitemI return InternalError(err, w, r) } - err = getUserNameStmt.QueryRow(userReply.ParentID).Scan(&title) + err = stmts.getUserName.QueryRow(userReply.ParentID).Scan(&title) if err == ErrNoRows { return LocalError("We weren't able to find the profile the reported post is supposed to be on", w, r, user) } else if err != nil { @@ -635,7 +635,7 @@ func routeReportSubmit(w http.ResponseWriter, r *http.Request, user User, sitemI title = "Profile: " + title content = userReply.Content + "\n\nOriginal Post: @" + strconv.Itoa(userReply.ParentID) } else if itemType == "topic" { - err = getTopicBasicStmt.QueryRow(itemID).Scan(&title, &content) + err = stmts.getTopicBasic.QueryRow(itemID).Scan(&title, &content) if err == ErrNoRows { return NotFound(w, r) } else if err != nil { @@ -653,7 +653,7 @@ func routeReportSubmit(w http.ResponseWriter, r *http.Request, user User, sitemI } var count int - rows, err := reportExistsStmt.Query(itemType + "_" + strconv.Itoa(itemID)) + rows, err := stmts.reportExists.Query(itemType + "_" + strconv.Itoa(itemID)) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -670,7 +670,7 @@ func routeReportSubmit(w http.ResponseWriter, r *http.Request, user User, sitemI // TODO: Repost attachments in the reports forum, so that the mods can see them // ? - Can we do this via the TopicStore? - res, err := createReportStmt.Exec(title, content, parseMessage(content, 0, ""), user.ID, user.ID, itemType+"_"+strconv.Itoa(itemID)) + res, err := stmts.createReport.Exec(title, content, parseMessage(content, 0, ""), user.ID, user.ID, itemType+"_"+strconv.Itoa(itemID)) if err != nil { return InternalError(err, w, r) } @@ -680,7 +680,7 @@ func routeReportSubmit(w http.ResponseWriter, r *http.Request, user User, sitemI return InternalError(err, w, r) } - _, err = addTopicsToForumStmt.Exec(1, fid) + _, err = stmts.addTopicsToForum.Exec(1, fid) if err != nil { return InternalError(err, w, r) } @@ -698,9 +698,6 @@ func routeAccountOwnEditCritical(w http.ResponseWriter, r *http.Request, user Us if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } pi := Page{"Edit Password", user, headerVars, tList, nil} if preRenderHooks["pre_render_account_own_edit_critical"] != nil { @@ -720,9 +717,6 @@ func routeAccountOwnEditCriticalSubmit(w http.ResponseWriter, r *http.Request, u if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } err := r.ParseForm() if err != nil { @@ -734,7 +728,7 @@ func routeAccountOwnEditCriticalSubmit(w http.ResponseWriter, r *http.Request, u newPassword := r.PostFormValue("account-new-password") confirmPassword := r.PostFormValue("account-confirm-password") - err = getPasswordStmt.QueryRow(user.ID).Scan(&realPassword, &salt) + err = stmts.getPassword.QueryRow(user.ID).Scan(&realPassword, &salt) if err == ErrNoRows { return LocalError("Your account no longer exists.", w, r, user) } else if err != nil { @@ -774,9 +768,7 @@ func routeAccountOwnEditAvatar(w http.ResponseWriter, r *http.Request, user User if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } + pi := Page{"Edit Avatar", user, headerVars, tList, nil} if preRenderHooks["pre_render_account_own_edit_avatar"] != nil { if runPreRenderHook("pre_render_account_own_edit_avatar", w, r, &user, &pi) { @@ -801,9 +793,6 @@ func routeAccountOwnEditAvatarSubmit(w http.ResponseWriter, r *http.Request, use if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } err := r.ParseMultipartForm(int64(megabyte)) if err != nil { @@ -884,9 +873,7 @@ func routeAccountOwnEditUsername(w http.ResponseWriter, r *http.Request, user Us if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } + pi := Page{"Edit Username", user, headerVars, tList, user.Name} if preRenderHooks["pre_render_account_own_edit_username"] != nil { if runPreRenderHook("pre_render_account_own_edit_username", w, r, &user, &pi) { @@ -905,9 +892,6 @@ func routeAccountOwnEditUsernameSubmit(w http.ResponseWriter, r *http.Request, u if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } err := r.ParseForm() if err != nil { return LocalError("Bad Form", w, r, user) @@ -939,22 +923,19 @@ func routeAccountOwnEditEmail(w http.ResponseWriter, r *http.Request, user User) if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } email := Email{UserID: user.ID} var emailList []interface{} - rows, err := getEmailsByUserStmt.Query(user.ID) + rows, err := stmts.getEmailsByUser.Query(user.ID) if err != nil { - log.Fatal(err) + return InternalError(err, w, r) } defer rows.Close() for rows.Next() { err := rows.Scan(&email.Email, &email.Validated, &email.Token) if err != nil { - log.Fatal(err) + return InternalError(err, w, r) } if email.Email == user.Email { @@ -964,7 +945,7 @@ func routeAccountOwnEditEmail(w http.ResponseWriter, r *http.Request, user User) } err = rows.Err() if err != nil { - log.Fatal(err) + return InternalError(err, w, r) } // Was this site migrated from another forum software? Most of them don't have multiple emails for a single user. @@ -992,20 +973,16 @@ func routeAccountOwnEditEmail(w http.ResponseWriter, r *http.Request, user User) return nil } -func routeAccountOwnEditEmailTokenSubmit(w http.ResponseWriter, r *http.Request, user User) RouteError { +func routeAccountOwnEditEmailTokenSubmit(w http.ResponseWriter, r *http.Request, user User, token string) RouteError { headerVars, ferr := UserCheck(w, r, &user) if ferr != nil { return ferr } - if !user.Loggedin { - return LocalError("You need to login to edit your account.", w, r, user) - } - token := r.URL.Path[len("/user/edit/token/"):] email := Email{UserID: user.ID} targetEmail := Email{UserID: user.ID} var emailList []interface{} - rows, err := getEmailsByUserStmt.Query(user.ID) + rows, err := stmts.getEmailsByUser.Query(user.ID) if err != nil { return InternalError(err, w, r) } @@ -1037,14 +1014,14 @@ func routeAccountOwnEditEmailTokenSubmit(w http.ResponseWriter, r *http.Request, return LocalError("That's not a valid token!", w, r, user) } - _, err = verifyEmailStmt.Exec(user.Email) + _, err = stmts.verifyEmail.Exec(user.Email) if err != nil { return InternalError(err, w, r) } // If Email Activation is on, then activate the account while we're here if headerVars.Settings["activation_type"] == 2 { - _, err = activateUserStmt.Exec(user.ID) + _, err = stmts.activateUser.Exec(user.ID) if err != nil { return InternalError(err, w, r) } @@ -1098,7 +1075,7 @@ func routeShowAttachment(w http.ResponseWriter, r *http.Request, user User, file var originTable string var originID, uploadedBy int - err = getAttachmentStmt.QueryRow(filename, sectionID, sectionTable).Scan(§ionID, §ionTable, &originID, &originTable, &uploadedBy, &filename) + err = stmts.getAttachment.QueryRow(filename, sectionID, sectionTable).Scan(§ionID, §ionTable, &originID, &originTable, &uploadedBy, &filename) if err == ErrNoRows { return NotFound(w, r) } else if err != nil { diff --git a/misc_test.go b/misc_test.go index 962b6056..0daef579 100644 --- a/misc_test.go +++ b/misc_test.go @@ -475,6 +475,21 @@ func TestPermsMiddleware(t *testing.T) { expect(t, ferr == nil, "Supermods should be allowed through supermod gates") // TODO: Loop over the Control Panel routes and make sure only supermods can get in + + user = getDummyUser() + + ferr = MemberOnly(dummyResponseRecorder, dummyRequest, *user) + expect(t, ferr != nil, "Blank users shouldn't be considered loggedin") + + user.Loggedin = false + ferr = MemberOnly(dummyResponseRecorder, dummyRequest, *user) + expect(t, ferr != nil, "Guests shouldn't be able to access member areas") + + user.Loggedin = true + ferr = MemberOnly(dummyResponseRecorder, dummyRequest, *user) + expect(t, ferr == nil, "Logged in users should be able to access member areas") + + // TODO: Loop over the /user/ routes and make sure only members can access the ones other than /user/username } func TestTopicStore(t *testing.T) { diff --git a/mod_routes.go b/mod_routes.go index 6792094a..a53b90a3 100644 --- a/mod_routes.go +++ b/mod_routes.go @@ -123,7 +123,7 @@ func routeDeleteTopic(w http.ResponseWriter, r *http.Request, user User) RouteEr } // ? - We might need to add soft-delete before we can do an action reply for this - /*_, err = createActionReplyStmt.Exec(tid,"delete",ipaddress,user.ID) + /*_, err = stmts.createActionReply.Exec(tid,"delete",ipaddress,user.ID) if err != nil { return InternalErrorJSQ(err,w,r,isJs) }*/ @@ -350,13 +350,13 @@ func routeReplyEditSubmit(w http.ResponseWriter, r *http.Request, user User) Rou // Get the Reply ID.. var tid int - err = getReplyTIDStmt.QueryRow(rid).Scan(&tid) + err = stmts.getReplyTID.QueryRow(rid).Scan(&tid) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } var fid int - err = getTopicFIDStmt.QueryRow(tid).Scan(&fid) + err = stmts.getTopicFID.QueryRow(tid).Scan(&fid) if err == ErrNoRows { return PreErrorJSQ("The parent topic doesn't exist.", w, r, isJs) } else if err != nil { @@ -373,7 +373,7 @@ func routeReplyEditSubmit(w http.ResponseWriter, r *http.Request, user User) Rou } content := html.EscapeString(preparseMessage(r.PostFormValue("edit_item"))) - _, err = editReplyStmt.Exec(content, parseMessage(content, fid, "forums"), rid) + _, err = stmts.editReply.Exec(content, parseMessage(content, fid, "forums"), rid) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -408,7 +408,7 @@ func routeReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user User) R } var fid int - err = getTopicFIDStmt.QueryRow(reply.ParentID).Scan(&fid) + err = stmts.getTopicFID.QueryRow(reply.ParentID).Scan(&fid) if err == ErrNoRows { return PreErrorJSQ("The parent topic doesn't exist.", w, r, isJs) } else if err != nil { @@ -472,7 +472,7 @@ func routeProfileReplyEditSubmit(w http.ResponseWriter, r *http.Request, user Us // Get the Reply ID.. var uid int - err = getUserReplyUIDStmt.QueryRow(rid).Scan(&uid) + err = stmts.getUserReplyUID.QueryRow(rid).Scan(&uid) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -482,7 +482,7 @@ func routeProfileReplyEditSubmit(w http.ResponseWriter, r *http.Request, user Us } content := html.EscapeString(preparseMessage(r.PostFormValue("edit_item"))) - _, err = editProfileReplyStmt.Exec(content, parseMessage(content, 0, ""), rid) + _, err = stmts.editProfileReply.Exec(content, parseMessage(content, 0, ""), rid) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -508,7 +508,7 @@ func routeProfileReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user } var uid int - err = getUserReplyUIDStmt.QueryRow(rid).Scan(&uid) + err = stmts.getUserReplyUID.QueryRow(rid).Scan(&uid) if err == ErrNoRows { return LocalErrorJSQ("The reply you tried to delete doesn't exist.", w, r, user, isJs) } else if err != nil { @@ -519,7 +519,7 @@ func routeProfileReplyDeleteSubmit(w http.ResponseWriter, r *http.Request, user return NoPermissionsJSQ(w, r, user, isJs) } - _, err = deleteProfileReplyStmt.Exec(rid) + _, err = stmts.deleteProfileReply.Exec(rid) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -546,7 +546,7 @@ func routeIps(w http.ResponseWriter, r *http.Request, user User) RouteError { var uid int var reqUserList = make(map[int]bool) - rows, err := findUsersByIPUsersStmt.Query(ip) + rows, err := stmts.findUsersByIPUsers.Query(ip) if err != nil { return InternalError(err, w, r) } @@ -564,7 +564,7 @@ func routeIps(w http.ResponseWriter, r *http.Request, user User) RouteError { return InternalError(err, w, r) } - rows2, err := findUsersByIPTopicsStmt.Query(ip) + rows2, err := stmts.findUsersByIPTopics.Query(ip) if err != nil { return InternalError(err, w, r) } @@ -582,7 +582,7 @@ func routeIps(w http.ResponseWriter, r *http.Request, user User) RouteError { return InternalError(err, w, r) } - rows3, err := findUsersByIPRepliesStmt.Query(ip) + rows3, err := stmts.findUsersByIPReplies.Query(ip) if err != nil { return InternalError(err, w, r) } diff --git a/mssql.go b/mssql.go index 2ce0cfd8..74f49379 100644 --- a/mssql.go +++ b/mssql.go @@ -20,16 +20,6 @@ import ( var dbInstance string = "" -var getActivityFeedByWatcherStmt *sql.Stmt -var getActivityCountByWatcherStmt *sql.Stmt -var todaysPostCountStmt *sql.Stmt -var todaysTopicCountStmt *sql.Stmt -var todaysReportCountStmt *sql.Stmt -var todaysNewUserCountStmt *sql.Stmt -var findUsersByIPUsersStmt *sql.Stmt -var findUsersByIPTopicsStmt *sql.Stmt -var findUsersByIPRepliesStmt *sql.Stmt - func init() { dbAdapter = "mssql" _initDatabase = initMSSQL diff --git a/mysql.go b/mysql.go index 08a2a3e9..fbba9ed0 100644 --- a/mysql.go +++ b/mysql.go @@ -16,15 +16,6 @@ import _ "github.com/go-sql-driver/mysql" import "./query_gen/lib" var dbCollation = "utf8mb4_general_ci" -var getActivityFeedByWatcherStmt *sql.Stmt -var getActivityCountByWatcherStmt *sql.Stmt -var todaysPostCountStmt *sql.Stmt -var todaysTopicCountStmt *sql.Stmt -var todaysReportCountStmt *sql.Stmt -var todaysNewUserCountStmt *sql.Stmt -var findUsersByIPUsersStmt *sql.Stmt -var findUsersByIPTopicsStmt *sql.Stmt -var findUsersByIPRepliesStmt *sql.Stmt func init() { dbAdapter = "mysql" @@ -75,54 +66,54 @@ func initMySQL() (err error) { // TODO: Is there a less noisy way of doing this for tests? log.Print("Preparing get_activity_feed_by_watcher statement.") - getActivityFeedByWatcherStmt, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid ASC LIMIT 8") + stmts.getActivityFeedByWatcher, err = db.Prepare("SELECT activity_stream_matches.asid, activity_stream.actor, activity_stream.targetUser, activity_stream.event, activity_stream.elementType, activity_stream.elementID FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ? ORDER BY activity_stream.asid ASC LIMIT 8") if err != nil { return err } log.Print("Preparing get_activity_count_by_watcher statement.") - getActivityCountByWatcherStmt, err = db.Prepare("SELECT count(*) FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ?") + stmts.getActivityCountByWatcher, err = db.Prepare("SELECT count(*) FROM `activity_stream_matches` INNER JOIN `activity_stream` ON activity_stream_matches.asid = activity_stream.asid AND activity_stream_matches.watcher != activity_stream.actor WHERE `watcher` = ?") if err != nil { return err } log.Print("Preparing todays_post_count statement.") - todaysPostCountStmt, err = db.Prepare("select count(*) from replies where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()") + stmts.todaysPostCount, err = db.Prepare("select count(*) from replies where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()") if err != nil { return err } log.Print("Preparing todays_topic_count statement.") - todaysTopicCountStmt, err = db.Prepare("select count(*) from topics where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()") + stmts.todaysTopicCount, err = db.Prepare("select count(*) from topics where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()") if err != nil { return err } log.Print("Preparing todays_report_count statement.") - todaysReportCountStmt, err = db.Prepare("select count(*) from topics where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp() and parentID = 1") + stmts.todaysReportCount, err = db.Prepare("select count(*) from topics where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp() and parentID = 1") if err != nil { return err } log.Print("Preparing todays_newuser_count statement.") - todaysNewUserCountStmt, err = db.Prepare("select count(*) from users where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()") + stmts.todaysNewUserCount, err = db.Prepare("select count(*) from users where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()") if err != nil { return err } log.Print("Preparing find_users_by_ip_users statement.") - findUsersByIPUsersStmt, err = db.Prepare("select uid from users where last_ip = ?") + stmts.findUsersByIPUsers, err = db.Prepare("select uid from users where last_ip = ?") if err != nil { return err } log.Print("Preparing find_users_by_ip_topics statement.") - findUsersByIPTopicsStmt, err = db.Prepare("select uid from users where uid in(select createdBy from topics where ipaddress = ?)") + stmts.findUsersByIPTopics, err = db.Prepare("select uid from users where uid in(select createdBy from topics where ipaddress = ?)") if err != nil { return err } log.Print("Preparing find_users_by_ip_replies statement.") - findUsersByIPRepliesStmt, err = db.Prepare("select uid from users where uid in(select createdBy from replies where ipaddress = ?)") + stmts.findUsersByIPReplies, err = db.Prepare("select uid from users where uid in(select createdBy from replies where ipaddress = ?)") return err } diff --git a/panel_routes.go b/panel_routes.go index 1839787b..74b2e1b3 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -63,7 +63,7 @@ func routePanel(w http.ResponseWriter, r *http.Request, user User) RouteError { } var postCount int - err = todaysPostCountStmt.QueryRow().Scan(&postCount) + err = stmts.todaysPostCount.QueryRow().Scan(&postCount) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -79,7 +79,7 @@ func routePanel(w http.ResponseWriter, r *http.Request, user User) RouteError { } var topicCount int - err = todaysTopicCountStmt.QueryRow().Scan(&topicCount) + err = stmts.todaysTopicCount.QueryRow().Scan(&topicCount) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -95,14 +95,14 @@ func routePanel(w http.ResponseWriter, r *http.Request, user User) RouteError { } var reportCount int - err = todaysReportCountStmt.QueryRow().Scan(&reportCount) + err = stmts.todaysReportCount.QueryRow().Scan(&reportCount) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } var reportInterval = "week" var newUserCount int - err = todaysNewUserCountStmt.QueryRow().Scan(&newUserCount) + err = stmts.todaysNewUserCount.QueryRow().Scan(&newUserCount) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -483,7 +483,7 @@ func routePanelForumsEditPermsSubmit(w http.ResponseWriter, r *http.Request, use } // TODO: Add this and replaceForumPermsForGroup into a transaction? - _, err = updateForumStmt.Exec(forum.Name, forum.Desc, forum.Active, "", fid) + _, err = stmts.updateForum.Exec(forum.Name, forum.Desc, forum.Active, "", fid) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -512,7 +512,7 @@ func routePanelSettings(w http.ResponseWriter, r *http.Request, user User) Route //log.Print("headerVars.Settings",headerVars.Settings) var settingList = make(map[string]interface{}) - rows, err := getSettingsStmt.Query() + rows, err := stmts.getSettings.Query() if err != nil { return InternalError(err, w, r) } @@ -572,7 +572,7 @@ func routePanelSetting(w http.ResponseWriter, r *http.Request, user User, sname } setting := Setting{sname, "", "", ""} - err := getSettingStmt.QueryRow(setting.Name).Scan(&setting.Content, &setting.Type) + err := stmts.getSetting.QueryRow(setting.Name).Scan(&setting.Content, &setting.Type) if err == ErrNoRows { return LocalError("The setting you want to edit doesn't exist.", w, r, user) } else if err != nil { @@ -630,7 +630,7 @@ func routePanelSettingEdit(w http.ResponseWriter, r *http.Request, user User, sn var stype, sconstraints string scontent := r.PostFormValue("setting-value") - err = getFullSettingStmt.QueryRow(sname).Scan(&sname, &stype, &sconstraints) + err = stmts.getFullSetting.QueryRow(sname).Scan(&sname, &stype, &sconstraints) if err == ErrNoRows { return LocalError("The setting you want to edit doesn't exist.", w, r, user) } else if err != nil { @@ -646,7 +646,7 @@ func routePanelSettingEdit(w http.ResponseWriter, r *http.Request, user User, sn } // TODO: Make this a method or function? - _, err = updateSettingStmt.Exec(scontent, sname) + _, err = stmts.updateSetting.Exec(scontent, sname) if err != nil { return InternalError(err, w, r) } @@ -707,7 +707,7 @@ func routePanelWordFiltersCreate(w http.ResponseWriter, r *http.Request, user Us // Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement replacement := strings.TrimSpace(r.PostFormValue("replacement")) - res, err := createWordFilterStmt.Exec(find, replacement) + res, err := stmts.createWordFilter.Exec(find, replacement) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -778,7 +778,7 @@ func routePanelWordFiltersEditSubmit(w http.ResponseWriter, r *http.Request, use // Unlike with find, it's okay if we leave this blank, as this means that the admin wants to remove the word entirely with no replacement replacement := strings.TrimSpace(r.PostFormValue("replacement")) - _, err = updateWordFilterStmt.Exec(find, replacement, id) + _, err = stmts.updateWordFilter.Exec(find, replacement, id) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -811,7 +811,7 @@ func routePanelWordFiltersDeleteSubmit(w http.ResponseWriter, r *http.Request, u return LocalErrorJSQ("The word filter ID must be an integer.", w, r, user, isJs) } - _, err = deleteWordFilterStmt.Exec(id) + _, err = stmts.deleteWordFilter.Exec(id) if err != nil { return InternalErrorJSQ(err, w, r, isJs) } @@ -874,7 +874,7 @@ func routePanelPluginsActivate(w http.ResponseWriter, r *http.Request, user User } var active bool - err := isPluginActiveStmt.QueryRow(uname).Scan(&active) + err := stmts.isPluginActive.QueryRow(uname).Scan(&active) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -894,13 +894,13 @@ func routePanelPluginsActivate(w http.ResponseWriter, r *http.Request, user User return LocalError("The plugin is already active", w, r, user) } //log.Print("updatePlugin") - _, err = updatePluginStmt.Exec(1, uname) + _, err = stmts.updatePlugin.Exec(1, uname) if err != nil { return InternalError(err, w, r) } } else { //log.Print("addPlugin") - _, err := addPluginStmt.Exec(uname, 1, 0) + _, err := stmts.addPlugin.Exec(uname, 1, 0) if err != nil { return InternalError(err, w, r) } @@ -936,7 +936,7 @@ func routePanelPluginsDeactivate(w http.ResponseWriter, r *http.Request, user Us } var active bool - err := isPluginActiveStmt.QueryRow(uname).Scan(&active) + err := stmts.isPluginActive.QueryRow(uname).Scan(&active) if err == ErrNoRows { return LocalError("The plugin you're trying to deactivate isn't active", w, r, user) } else if err != nil { @@ -946,7 +946,7 @@ func routePanelPluginsDeactivate(w http.ResponseWriter, r *http.Request, user Us if !active { return LocalError("The plugin you're trying to deactivate isn't active", w, r, user) } - _, err = updatePluginStmt.Exec(0, uname) + _, err = stmts.updatePlugin.Exec(0, uname) if err != nil { return InternalError(err, w, r) } @@ -985,7 +985,7 @@ func routePanelPluginsInstall(w http.ResponseWriter, r *http.Request, user User, } var active bool - err := isPluginActiveStmt.QueryRow(uname).Scan(&active) + err := stmts.isPluginActive.QueryRow(uname).Scan(&active) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -1006,16 +1006,16 @@ func routePanelPluginsInstall(w http.ResponseWriter, r *http.Request, user User, } if hasPlugin { - _, err = updatePluginInstallStmt.Exec(1, uname) + _, err = stmts.updatePluginInstall.Exec(1, uname) if err != nil { return InternalError(err, w, r) } - _, err = updatePluginStmt.Exec(1, uname) + _, err = stmts.updatePlugin.Exec(1, uname) if err != nil { return InternalError(err, w, r) } } else { - _, err := addPluginStmt.Exec(uname, 1, 1) + _, err := stmts.addPlugin.Exec(uname, 1, 1) if err != nil { return InternalError(err, w, r) } @@ -1046,7 +1046,7 @@ func routePanelUsers(w http.ResponseWriter, r *http.Request, user User) RouteErr var userList []User // TODO: Move this into the UserStore - rows, err := getUsersOffsetStmt.Query(offset, perPage) + rows, err := stmts.getUsersOffset.Query(offset, perPage) if err != nil { return InternalError(err, w, r) } @@ -1216,7 +1216,7 @@ func routePanelUsersEditSubmit(w http.ResponseWriter, r *http.Request, user User return LocalError("You need the EditUserGroupSuperMod permission to assign someone to a super mod group.", w, r, user) } - _, err = updateUserStmt.Exec(newname, newemail, newgroup, targetUser.ID) + _, err = stmts.updateUser.Exec(newname, newemail, newgroup, targetUser.ID) if err != nil { return InternalError(err, w, r) } @@ -1516,7 +1516,7 @@ func routePanelGroupsEditSubmit(w http.ResponseWriter, r *http.Request, user Use } // TODO: Move this to *Group - _, err = updateGroupStmt.Exec(gname, gtag, gid) + _, err = stmts.updateGroup.Exec(gname, gtag, gid) if err != nil { return InternalError(err, w, r) } @@ -1581,7 +1581,7 @@ func routePanelGroupsEditPermsSubmit(w http.ResponseWriter, r *http.Request, use if err != nil { return LocalError("Unable to marshal the data", w, r, user) } - _, err = updateGroupPermsStmt.Exec(pjson, gid) + _, err = stmts.updateGroupPerms.Exec(pjson, gid) if err != nil { return InternalError(err, w, r) } @@ -1696,7 +1696,7 @@ func routePanelThemesSetDefault(w http.ResponseWriter, r *http.Request, user Use var isDefault bool log.Print("uname", uname) // TODO: Do we need to log this? - err := isThemeDefaultStmt.QueryRow(uname).Scan(&isDefault) + err := stmts.isThemeDefault.QueryRow(uname).Scan(&isDefault) if err != nil && err != ErrNoRows { return InternalError(err, w, r) } @@ -1707,12 +1707,12 @@ func routePanelThemesSetDefault(w http.ResponseWriter, r *http.Request, user Use if isDefault { return LocalError("The theme is already active", w, r, user) } - _, err = updateThemeStmt.Exec(1, uname) + _, err = stmts.updateTheme.Exec(1, uname) if err != nil { return InternalError(err, w, r) } } else { - _, err := addThemeStmt.Exec(uname, 1) + _, err := stmts.addTheme.Exec(uname, 1) if err != nil { return InternalError(err, w, r) } @@ -1721,7 +1721,7 @@ func routePanelThemesSetDefault(w http.ResponseWriter, r *http.Request, user Use // TODO: Make this less racey changeDefaultThemeMutex.Lock() defaultTheme := defaultThemeBox.Load().(string) - _, err = updateThemeStmt.Exec(0, defaultTheme) + _, err = stmts.updateTheme.Exec(0, defaultTheme) if err != nil { return InternalError(err, w, r) } @@ -1803,7 +1803,7 @@ func routePanelLogsMod(w http.ResponseWriter, r *http.Request, user User) RouteE } var logCount int - err := modlogCountStmt.QueryRow().Scan(&logCount) + err := stmts.modlogCount.QueryRow().Scan(&logCount) if err != nil { return InternalError(err, w, r) } @@ -1812,7 +1812,7 @@ func routePanelLogsMod(w http.ResponseWriter, r *http.Request, user User) RouteE perPage := 10 offset, page, lastPage := pageOffset(logCount, page, perPage) - rows, err := getModlogsOffsetStmt.Query(offset, perPage) + rows, err := stmts.getModlogsOffset.Query(offset, perPage) if err != nil { return InternalError(err, w, r) } diff --git a/pgsql.go b/pgsql.go index 446e1966..d1ff62b4 100644 --- a/pgsql.go +++ b/pgsql.go @@ -13,12 +13,6 @@ import "./query_gen/lib" // TODO: Add support for SSL for all database drivers, not just pgsql var db_sslmode = "disable" // verify-full -var get_activity_feed_by_watcher_stmt *sql.Stmt -var get_activity_count_by_watcher_stmt *sql.Stmt -var todays_post_count_stmt *sql.Stmt -var todays_topic_count_stmt *sql.Stmt -var todays_report_count_stmt *sql.Stmt -var todays_newuser_count_stmt *sql.Stmt func init() { db_adapter = "pgsql" diff --git a/query_gen/lib/mssql.go b/query_gen/lib/mssql.go index e6bb417e..a5b33881 100644 --- a/query_gen/lib/mssql.go +++ b/query_gen/lib/mssql.go @@ -491,14 +491,6 @@ func (adapter *MssqlAdapter) SimpleSelect(name string, table string, columns str } } - /*if limiter.MaxCount != "" { - if limiter.MaxCount == "?" { - substituteCount++ - limiter.MaxCount = "?" + strconv.Itoa(substituteCount) - } - querystr = "TOP " + limiter.MaxCount + " " + querystr - }*/ - // ! Does this work without an offset? if limiter.MaxCount != "" { if limiter.MaxCount == "?" { @@ -1086,10 +1078,10 @@ func (adapter *MssqlAdapter) Write() error { stmt := adapter.Buffer[name] // TODO: Add support for create-table? Table creation might be a little complex for Go to do outside a SQL file :( if stmt.Type != "create-table" { - stmts += "var " + name + "Stmt *sql.Stmt\n" + stmts += "\t" + name + " *sql.Stmt\n" body += ` log.Print("Preparing ` + name + ` statement.") - ` + name + `Stmt, err = db.Prepare("` + stmt.Contents + `") + stmts.` + name + `, err = db.Prepare("` + stmt.Contents + `") if err != nil { log.Print("Bad Query: ","` + stmt.Contents + `") return err @@ -1098,6 +1090,7 @@ func (adapter *MssqlAdapter) Write() error { } } + // TODO: Move these custom queries out of this file out := `// +build mssql // This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. @@ -1107,7 +1100,21 @@ import "log" import "database/sql" // nolint +type Stmts struct { ` + stmts + ` + getActivityFeedByWatcher *sql.Stmt + getActivityCountByWatcher *sql.Stmt + todaysPostCount *sql.Stmt + todaysTopicCount *sql.Stmt + todaysReportCount *sql.Stmt + todaysNewUserCount *sql.Stmt + findUsersByIPUsers *sql.Stmt + findUsersByIPTopics *sql.Stmt + findUsersByIPReplies *sql.Stmt + + Mocks bool +} + // nolint func _gen_mssql() (err error) { if dev.DebugMode { diff --git a/query_gen/lib/mysql.go b/query_gen/lib/mysql.go index 908c73c9..69d5af74 100644 --- a/query_gen/lib/mysql.go +++ b/query_gen/lib/mysql.go @@ -129,10 +129,10 @@ func (adapter *MysqlAdapter) SimpleInsert(name string, table string, columns str } querystr += field.Name + "," } - querystr = querystr[0 : len(querystr)-1] + querystr = querystr[0:len(querystr)-1] + ")" - adapter.pushStatement(name, "insert", querystr+")") - return querystr + ")", nil + adapter.pushStatement(name, "insert", querystr) + return querystr, nil } func (adapter *MysqlAdapter) buildColumns(columns string) (querystr string) { @@ -307,7 +307,7 @@ func (adapter *MysqlAdapter) Purge(name string, table string) (string, error) { // TODO: Add support for BETWEEN x.x func (adapter *MysqlAdapter) buildWhere(where string) (querystr string, err error) { if len(where) != 0 { - querystr += " WHERE" + querystr = " WHERE" for _, loc := range processWhere(where) { for _, token := range loc.Expr { switch token.Type { @@ -330,7 +330,7 @@ func (adapter *MysqlAdapter) buildWhere(where string) (querystr string, err erro func (adapter *MysqlAdapter) buildOrderby(orderby string) (querystr string) { if len(orderby) != 0 { - querystr += " ORDER BY " + querystr = " ORDER BY " for _, column := range processOrderby(orderby) { // TODO: We might want to escape this column querystr += column.Column + " " + strings.ToUpper(column.Order) + "," @@ -468,7 +468,7 @@ func (adapter *MysqlAdapter) buildJoiners(joiners string) (querystr string) { // Add support for BETWEEN x.x func (adapter *MysqlAdapter) buildJoinWhere(where string) (querystr string, err error) { if len(where) != 0 { - querystr += " WHERE" + querystr = " WHERE" for _, loc := range processWhere(where) { for _, token := range loc.Expr { switch token.Type { @@ -496,24 +496,22 @@ func (adapter *MysqlAdapter) buildJoinWhere(where string) (querystr string, err func (adapter *MysqlAdapter) buildLimit(limit string) (querystr string) { if limit != "" { - querystr += " LIMIT " + limit + querystr = " LIMIT " + limit } return querystr } func (adapter *MysqlAdapter) buildJoinColumns(columns string) (querystr string) { for _, column := range processColumns(columns) { - var source, alias string - // Escape the column names, just in case we've used a reserved keyword + var source = column.Left if column.Table != "" { - source = "`" + column.Table + "`.`" + column.Left + "`" - } else if column.Type == "function" { - source = column.Left - } else { - source = "`" + column.Left + "`" + source = "`" + column.Table + "`.`" + source + "`" + } else if column.Type != "function" { + source = "`" + source + "`" } + var alias string if column.Alias != "" { alias = " AS `" + column.Alias + "`" } @@ -563,19 +561,19 @@ func (adapter *MysqlAdapter) Write() error { stmt := adapter.Buffer[name] // ? - Table creation might be a little complex for Go to do outside a SQL file :( if stmt.Type == "upsert" { - stmts += "var " + name + "Stmt *qgen.MySQLUpsertCallback\n" + stmts += "\t" + name + " *qgen.MySQLUpsertCallback\n" body += ` log.Print("Preparing ` + name + ` statement.") - ` + name + `Stmt, err = qgen.PrepareMySQLUpsertCallback(db, "` + stmt.Contents + `") + stmts.` + name + `, err = qgen.PrepareMySQLUpsertCallback(db, "` + stmt.Contents + `") if err != nil { return err } ` } else if stmt.Type != "create-table" { - stmts += "var " + name + "Stmt *sql.Stmt\n" + stmts += "\t" + name + " *sql.Stmt\n" body += ` log.Print("Preparing ` + name + ` statement.") - ` + name + `Stmt, err = db.Prepare("` + stmt.Contents + `") + stmts.` + name + `, err = db.Prepare("` + stmt.Contents + `") if err != nil { return err } @@ -583,6 +581,7 @@ func (adapter *MysqlAdapter) Write() error { } } + // TODO: Move these custom queries out of this file out := `// +build !pgsql, !sqlite, !mssql /* This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. */ @@ -594,7 +593,21 @@ import "database/sql" //import "./query_gen/lib" // nolint +type Stmts struct { ` + stmts + ` + getActivityFeedByWatcher *sql.Stmt + getActivityCountByWatcher *sql.Stmt + todaysPostCount *sql.Stmt + todaysTopicCount *sql.Stmt + todaysReportCount *sql.Stmt + todaysNewUserCount *sql.Stmt + findUsersByIPUsers *sql.Stmt + findUsersByIPTopics *sql.Stmt + findUsersByIPReplies *sql.Stmt + + Mocks bool +} + // nolint func _gen_mysql() (err error) { if dev.DebugMode { diff --git a/query_gen/lib/pgsql.go b/query_gen/lib/pgsql.go index 8c93a225..642954b4 100644 --- a/query_gen/lib/pgsql.go +++ b/query_gen/lib/pgsql.go @@ -327,10 +327,10 @@ func (adapter *PgsqlAdapter) Write() error { stmt := adapter.Buffer[name] // TODO: Add support for create-table? Table creation might be a little complex for Go to do outside a SQL file :( if stmt.Type != "create-table" { - stmts += "var " + name + "Stmt *sql.Stmt\n" + stmts += "\t" + name + " *sql.Stmt\n" body += ` log.Print("Preparing ` + name + ` statement.") - ` + name + `Stmt, err = db.Prepare("` + stmt.Contents + `") + stmts.` + name + `, err = db.Prepare("` + stmt.Contents + `") if err != nil { return err } @@ -338,6 +338,7 @@ func (adapter *PgsqlAdapter) Write() error { } } + // TODO: Move these custom queries out of this file out := `// +build pgsql // This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. @@ -347,7 +348,21 @@ import "log" import "database/sql" // nolint +type Stmts struct { ` + stmts + ` + getActivityFeedByWatcher *sql.Stmt + getActivityCountByWatcher *sql.Stmt + todaysPostCount *sql.Stmt + todaysTopicCount *sql.Stmt + todaysReportCount *sql.Stmt + todaysNewUserCount *sql.Stmt + findUsersByIPUsers *sql.Stmt + findUsersByIPTopics *sql.Stmt + findUsersByIPReplies *sql.Stmt + + Mocks bool +} + // nolint func _gen_pgsql() (err error) { if dev.DebugMode { diff --git a/reply.go b/reply.go index fb10d3f6..aad06070 100644 --- a/reply.go +++ b/reply.go @@ -65,7 +65,7 @@ var ErrAlreadyLiked = errors.New("You already liked this!") // TODO: Wrap these queries in a transaction to make sure the state is consistent func (reply *Reply) Like(uid int) (err error) { var rid int // unused, just here to avoid mutating reply.ID - err = hasLikedReplyStmt.QueryRow(uid, reply.ID).Scan(&rid) + err = stmts.hasLikedReply.QueryRow(uid, reply.ID).Scan(&rid) if err != nil && err != ErrNoRows { return err } else if err != ErrNoRows { @@ -73,21 +73,21 @@ func (reply *Reply) Like(uid int) (err error) { } score := 1 - _, err = createLikeStmt.Exec(score, reply.ID, "replies", uid) + _, err = stmts.createLike.Exec(score, reply.ID, "replies", uid) if err != nil { return err } - _, err = addLikesToReplyStmt.Exec(1, reply.ID) + _, err = stmts.addLikesToReply.Exec(1, reply.ID) return err } // TODO: Write tests for this func (reply *Reply) Delete() error { - _, err := deleteReplyStmt.Exec(reply.ID) + _, err := stmts.deleteReply.Exec(reply.ID) if err != nil { return err } - _, err = removeRepliesFromTopicStmt.Exec(1, reply.ParentID) + _, err = stmts.removeRepliesFromTopic.Exec(1, reply.ParentID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(reply.ParentID) @@ -100,6 +100,7 @@ func (reply *Reply) Copy() Reply { return *reply } +// TODO: Refactor this to stop hitting the global stmt store type ReplyStore interface { Get(id int) (*Reply, error) Create(tid int, content string, ipaddress string, fid int, uid int) (id int, err error) @@ -114,14 +115,14 @@ func NewSQLReplyStore() *SQLReplyStore { func (store *SQLReplyStore) Get(id int) (*Reply, error) { reply := Reply{ID: id} - err := getReplyStmt.QueryRow(id).Scan(&reply.ParentID, &reply.Content, &reply.CreatedBy, &reply.CreatedAt, &reply.LastEdit, &reply.LastEditBy, &reply.IPAddress, &reply.LikeCount) + err := stmts.getReply.QueryRow(id).Scan(&reply.ParentID, &reply.Content, &reply.CreatedBy, &reply.CreatedAt, &reply.LastEdit, &reply.LastEditBy, &reply.IPAddress, &reply.LikeCount) return &reply, err } // TODO: Write a test for this func (store *SQLReplyStore) Create(tid int, content string, ipaddress string, fid int, uid int) (id int, err error) { wcount := wordCount(content) - res, err := createReplyStmt.Exec(tid, content, parseMessage(content, fid, "forums"), ipaddress, wcount, uid) + res, err := stmts.createReply.Exec(tid, content, parseMessage(content, fid, "forums"), ipaddress, wcount, uid) if err != nil { return 0, err } @@ -130,7 +131,7 @@ func (store *SQLReplyStore) Create(tid int, content string, ipaddress string, fi return 0, err } - _, err = addRepliesToTopicStmt.Exec(1, uid, tid) + _, err = stmts.addRepliesToTopic.Exec(1, uid, tid) if err != nil { return int(lastID), err } @@ -145,6 +146,7 @@ type ProfileReplyStore interface { Get(id int) (*Reply, error) } +// TODO: Refactor this to stop using the global stmt store type SQLProfileReplyStore struct { } @@ -154,6 +156,6 @@ func NewSQLProfileReplyStore() *SQLProfileReplyStore { func (store *SQLProfileReplyStore) Get(id int) (*Reply, error) { reply := Reply{ID: id} - err := getUserReplyStmt.QueryRow(id).Scan(&reply.ParentID, &reply.Content, &reply.CreatedBy, &reply.CreatedAt, &reply.LastEdit, &reply.LastEditBy, &reply.IPAddress) + err := stmts.getUserReply.QueryRow(id).Scan(&reply.ParentID, &reply.Content, &reply.CreatedBy, &reply.CreatedAt, &reply.LastEdit, &reply.LastEditBy, &reply.IPAddress) return &reply, err } diff --git a/router_gen/main.go b/router_gen/main.go index e5db8fb3..4213c66f 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -26,8 +26,20 @@ func main() { end = len(route.Path) - 1 } out += "\n\t\tcase \"" + route.Path[0:end] + "\":" - if route.Before != "" { - out += "\n\t\t\t" + route.Before + if len(route.RunBefore) > 0 { + for _, runnable := range route.RunBefore { + if runnable.Literal { + out += "\n\t\t\t\t\t" + runnable.Contents + } else { + out += ` + err = ` + runnable.Contents + `(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + ` + } + } } out += "\n\t\t\terr = " + route.Name + "(w,req,user" for _, item := range route.Vars { @@ -48,14 +60,18 @@ func main() { } out += ` case "` + group.Path[0:end] + `":` - for _, callback := range group.Before { - out += ` - err = ` + callback + `(w,req,user) + for _, runnable := range group.RunBefore { + if runnable.Literal { + out += "\t\t\t" + runnable.Contents + } else { + out += ` + err = ` + runnable.Contents + `(w,req,user) if err != nil { router.handleError(err,w,req,user) return } ` + } } out += "\n\t\t\tswitch(req.URL.Path) {" @@ -67,8 +83,20 @@ func main() { } out += "\n\t\t\t\tcase \"" + route.Path + "\":" - if route.Before != "" { - out += "\n\t\t\t\t\t" + route.Before + if len(route.RunBefore) > 0 { + for _, runnable := range route.RunBefore { + if runnable.Literal { + out += "\n\t\t\t\t\t" + runnable.Contents + } else { + out += ` + err = ` + runnable.Contents + `(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + ` + } + } } out += "\n\t\t\t\t\terr = " + route.Name + "(w,req,user" for _, item := range route.Vars { @@ -79,8 +107,20 @@ func main() { if defaultRoute.Name != "" { out += "\n\t\t\t\tdefault:" - if defaultRoute.Before != "" { - out += "\n\t\t\t\t\t" + defaultRoute.Before + if len(defaultRoute.RunBefore) > 0 { + for _, runnable := range defaultRoute.RunBefore { + if runnable.Literal { + out += "\n\t\t\t\t\t" + runnable.Contents + } else { + out += ` + err = ` + runnable.Contents + `(w,req,user) + if err != nil { + router.handleError(err,w,req,user) + return + } + ` + } + } } out += "\n\t\t\t\t\terr = " + defaultRoute.Name + "(w,req,user" for _, item := range defaultRoute.Vars { diff --git a/router_gen/routes.go b/router_gen/routes.go index 2a9f88a6..ec37365f 100644 --- a/router_gen/routes.go +++ b/router_gen/routes.go @@ -1,32 +1,51 @@ package main type RouteImpl struct { - Name string - Path string - Before string - Vars []string + Name string + Path string + Vars []string + RunBefore []Runnable } type RouteGroup struct { Path string RouteList []*RouteImpl - Before []string + RunBefore []Runnable } -func addRoute(fname string, path string, before string, vars ...string) { - routeList = append(routeList, &RouteImpl{fname, path, before, vars}) +type Runnable struct { + Contents string + Literal bool +} + +func addRoute(route *RouteImpl) { + routeList = append(routeList, route) +} + +func (route *RouteImpl) Before(item string, literal ...bool) *RouteImpl { + var litItem bool + if len(literal) > 0 { + litItem = literal[0] + } + route.RunBefore = append(route.RunBefore, Runnable{item, litItem}) + return route } func newRouteGroup(path string, routes ...*RouteImpl) *RouteGroup { - return &RouteGroup{path, routes, []string{}} + return &RouteGroup{path, routes, []Runnable{}} } func addRouteGroup(routeGroup *RouteGroup) { routeGroups = append(routeGroups, routeGroup) } -func (group *RouteGroup) RunBefore(line string) { - group.Before = append(group.Before, line) +func (group *RouteGroup) Before(line string, literal ...bool) *RouteGroup { + var litItem bool + if len(literal) > 0 { + litItem = literal[0] + } + group.RunBefore = append(group.RunBefore, Runnable{line, litItem}) + return group } func (group *RouteGroup) Routes(routes ...*RouteImpl) { @@ -34,88 +53,101 @@ func (group *RouteGroup) Routes(routes ...*RouteImpl) { } func blankRoute() *RouteImpl { - return &RouteImpl{"", "", "", []string{}} + return &RouteImpl{"", "", []string{}, []Runnable{}} } func Route(fname string, path string, args ...string) *RouteImpl { - var before = "" - if len(args) > 0 { - before = args[0] - args = args[1:] - } - return &RouteImpl{fname, path, before, args} + return &RouteImpl{fname, path, args, []Runnable{}} } func routes() { //addRoute("default_route","","") - addRoute("routeAPI", "/api/", "") + addRoute(Route("routeAPI", "/api/")) ///addRoute("routeStatic","/static/","req.URL.Path += extra_data") - addRoute("routeOverview", "/overview/", "") + addRoute(Route("routeOverview", "/overview/")) //addRoute("routeCustomPage","/pages/",""/*,"&extra_data"*/) - addRoute("routeForums", "/forums/", "" /*,"&forums"*/) - addRoute("routeForum", "/forum/", "", "extra_data") + addRoute(Route("routeForums", "/forums/" /*,"&forums"*/)) + addRoute(Route("routeForum", "/forum/", "extra_data")) //addRoute("routeTopicCreate","/topics/create/","","extra_data") //addRoute("routeTopics","/topics/",""/*,"&groups","&forums"*/) - addRoute("routeChangeTheme", "/theme/", "") - addRoute("routeShowAttachment", "/attachs/", "", "extra_data") + addRoute(Route("routeChangeTheme", "/theme/")) + addRoute(Route("routeShowAttachment", "/attachs/", "extra_data")) reportGroup := newRouteGroup("/report/", - Route("routeReportSubmit", "/report/submit/", "", "extra_data"), - ) + Route("routeReportSubmit", "/report/submit/", "extra_data"), + ).Before("MemberOnly") addRouteGroup(reportGroup) topicGroup := newRouteGroup("/topics/", Route("routeTopics", "/topics/"), - Route("routeTopicCreate", "/topics/create/", "", "extra_data"), + Route("routeTopicCreate", "/topics/create/", "extra_data").Before("MemberOnly"), ) addRouteGroup(topicGroup) buildPanelRoutes() + buildUserRoutes() +} + +// TODO: Test the email token route +// TODO: Add a BeforeExcept method? +func buildUserRoutes() { + userGroup := newRouteGroup("/user/") //.Before("MemberOnly") + userGroup.Routes( + Route("routeProfile", "/user/").Before("req.URL.Path += extra_data", true), + Route("routeAccountOwnEditCritical", "/user/edit/critical/").Before("MemberOnly"), + Route("routeAccountOwnEditCriticalSubmit", "/user/edit/critical/submit/").Before("MemberOnly"), + Route("routeAccountOwnEditAvatar", "/user/edit/avatar/").Before("MemberOnly"), + Route("routeAccountOwnEditAvatarSubmit", "/user/edit/avatar/submit/").Before("MemberOnly"), + Route("routeAccountOwnEditUsername", "/user/edit/username/").Before("MemberOnly"), + Route("routeAccountOwnEditUsernameSubmit", "/user/edit/username/submit/").Before("MemberOnly"), + Route("routeAccountOwnEditEmail", "/user/edit/email/").Before("MemberOnly"), + Route("routeAccountOwnEditEmailTokenSubmit", "/user/edit/token/", "extra_data").Before("MemberOnly"), + ) + addRouteGroup(userGroup) } func buildPanelRoutes() { - panelGroup := newRouteGroup("/panel/") - panelGroup.RunBefore("SuperModOnly") + panelGroup := newRouteGroup("/panel/").Before("SuperModOnly") panelGroup.Routes( Route("routePanel", "/panel/"), Route("routePanelForums", "/panel/forums/"), Route("routePanelForumsCreateSubmit", "/panel/forums/create/"), - Route("routePanelForumsDelete", "/panel/forums/delete/", "", "extra_data"), - Route("routePanelForumsDeleteSubmit", "/panel/forums/delete/submit/", "", "extra_data"), - Route("routePanelForumsEdit", "/panel/forums/edit/", "", "extra_data"), - Route("routePanelForumsEditSubmit", "/panel/forums/edit/submit/", "", "extra_data"), - Route("routePanelForumsEditPermsSubmit", "/panel/forums/edit/perms/submit/", "", "extra_data"), + Route("routePanelForumsDelete", "/panel/forums/delete/", "extra_data"), + Route("routePanelForumsDeleteSubmit", "/panel/forums/delete/submit/", "extra_data"), + Route("routePanelForumsEdit", "/panel/forums/edit/", "extra_data"), + Route("routePanelForumsEditSubmit", "/panel/forums/edit/submit/", "extra_data"), + Route("routePanelForumsEditPermsSubmit", "/panel/forums/edit/perms/submit/", "extra_data"), Route("routePanelSettings", "/panel/settings/"), - Route("routePanelSetting", "/panel/settings/edit/", "", "extra_data"), - Route("routePanelSettingEdit", "/panel/settings/edit/submit/", "", "extra_data"), + Route("routePanelSetting", "/panel/settings/edit/", "extra_data"), + Route("routePanelSettingEdit", "/panel/settings/edit/submit/", "extra_data"), Route("routePanelWordFilters", "/panel/settings/word-filters/"), Route("routePanelWordFiltersCreate", "/panel/settings/word-filters/create/"), - Route("routePanelWordFiltersEdit", "/panel/settings/word-filters/edit/", "", "extra_data"), - Route("routePanelWordFiltersEditSubmit", "/panel/settings/word-filters/edit/submit/", "", "extra_data"), - Route("routePanelWordFiltersDeleteSubmit", "/panel/settings/word-filters/delete/submit/", "", "extra_data"), + Route("routePanelWordFiltersEdit", "/panel/settings/word-filters/edit/", "extra_data"), + Route("routePanelWordFiltersEditSubmit", "/panel/settings/word-filters/edit/submit/", "extra_data"), + Route("routePanelWordFiltersDeleteSubmit", "/panel/settings/word-filters/delete/submit/", "extra_data"), Route("routePanelThemes", "/panel/themes/"), - Route("routePanelThemesSetDefault", "/panel/themes/default/", "", "extra_data"), + Route("routePanelThemesSetDefault", "/panel/themes/default/", "extra_data"), Route("routePanelPlugins", "/panel/plugins/"), - Route("routePanelPluginsActivate", "/panel/plugins/activate/", "", "extra_data"), - Route("routePanelPluginsDeactivate", "/panel/plugins/deactivate/", "", "extra_data"), - Route("routePanelPluginsInstall", "/panel/plugins/install/", "", "extra_data"), + Route("routePanelPluginsActivate", "/panel/plugins/activate/", "extra_data"), + Route("routePanelPluginsDeactivate", "/panel/plugins/deactivate/", "extra_data"), + Route("routePanelPluginsInstall", "/panel/plugins/install/", "extra_data"), Route("routePanelUsers", "/panel/users/"), - Route("routePanelUsersEdit", "/panel/users/edit/", "", "extra_data"), - Route("routePanelUsersEditSubmit", "/panel/users/edit/submit/", "", "extra_data"), + Route("routePanelUsersEdit", "/panel/users/edit/", "extra_data"), + Route("routePanelUsersEditSubmit", "/panel/users/edit/submit/", "extra_data"), Route("routePanelGroups", "/panel/groups/"), - Route("routePanelGroupsEdit", "/panel/groups/edit/", "", "extra_data"), - Route("routePanelGroupsEditPerms", "/panel/groups/edit/perms/", "", "extra_data"), - Route("routePanelGroupsEditSubmit", "/panel/groups/edit/submit/", "", "extra_data"), - Route("routePanelGroupsEditPermsSubmit", "/panel/groups/edit/perms/submit/", "", "extra_data"), + Route("routePanelGroupsEdit", "/panel/groups/edit/", "extra_data"), + Route("routePanelGroupsEditPerms", "/panel/groups/edit/perms/", "extra_data"), + Route("routePanelGroupsEditSubmit", "/panel/groups/edit/submit/", "extra_data"), + Route("routePanelGroupsEditPermsSubmit", "/panel/groups/edit/perms/submit/", "extra_data"), Route("routePanelGroupsCreateSubmit", "/panel/groups/create/"), - Route("routePanelBackups", "/panel/backups/", "", "extra_data"), + Route("routePanelBackups", "/panel/backups/", "extra_data"), Route("routePanelLogsMod", "/panel/logs/mod/"), Route("routePanelDebug", "/panel/debug/"), ) diff --git a/routes.go b/routes.go index f7f9fa25..6705bbbc 100644 --- a/routes.go +++ b/routes.go @@ -351,7 +351,7 @@ func routeForum(w http.ResponseWriter, r *http.Request, user User, sfid string) } // TODO: Move this to *Forum - rows, err := getForumTopicsOffsetStmt.Query(fid, offset, config.ItemsPerPage) + rows, err := stmts.getForumTopicsOffset.Query(fid, offset, config.ItemsPerPage) if err != nil { return InternalError(err, w, r) } @@ -558,7 +558,7 @@ func routeTopicID(w http.ResponseWriter, r *http.Request, user User) RouteError tpage := TopicPage{topic.Title, user, headerVars, replyList, topic, page, lastPage} // Get the replies.. - rows, err := getTopicRepliesOffsetStmt.Query(topic.ID, offset, config.ItemsPerPage) + rows, err := stmts.getTopicRepliesOffset.Query(topic.ID, offset, config.ItemsPerPage) if err == ErrNoRows { return LocalError("Bad Page. Some of the posts may have been deleted or you got here by directly typing in the page number.", w, r, user) } else if err != nil { @@ -684,7 +684,7 @@ func routeProfile(w http.ResponseWriter, r *http.Request, user User) RouteError } // Get the replies.. - rows, err := getProfileRepliesStmt.Query(puser.ID) + rows, err := stmts.getProfileReplies.Query(puser.ID) if err != nil { return InternalError(err, w, r) } @@ -904,7 +904,7 @@ func routeRegisterSubmit(w http.ResponseWriter, r *http.Request, user User) Rout if err != nil { return InternalError(err, w, r) } - _, err = addEmailStmt.Exec(email, uid, 0, token) + _, err = stmts.addEmail.Exec(email, uid, 0, token) if err != nil { return InternalError(err, w, r) } @@ -946,7 +946,7 @@ func routeChangeTheme(w http.ResponseWriter, r *http.Request, user User) RouteEr // TODO: Store the current theme in the user's account? /*if user.Loggedin { - _, err = change_theme_stmt.Exec(newTheme, user.ID) + _, err = stmts.changeTheme.Exec(newTheme, user.ID) if err != nil { return InternalError(err, w, r) } @@ -986,7 +986,7 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user User) RouteError { return PreErrorJS("Invalid asid", w, r) } - _, err = deleteActivityStreamMatchStmt.Exec(user.ID, asid) + _, err = stmts.deleteActivityStreamMatch.Exec(user.ID, asid) if err != nil { return InternalError(err, w, r) } @@ -1000,14 +1000,14 @@ func routeAPI(w http.ResponseWriter, r *http.Request, user User) RouteError { var asid, actorID, targetUserID, elementID int var msgCount int - err = getActivityCountByWatcherStmt.QueryRow(user.ID).Scan(&msgCount) + err = stmts.getActivityCountByWatcher.QueryRow(user.ID).Scan(&msgCount) if err == ErrNoRows { return PreErrorJS("Couldn't find the parent topic", w, r) } else if err != nil { return InternalErrorJS(err, w, r) } - rows, err := getActivityFeedByWatcherStmt.Query(user.ID) + rows, err := stmts.getActivityFeedByWatcher.Query(user.ID) if err != nil { return InternalErrorJS(err, w, r) } diff --git a/routes_common.go b/routes_common.go index f15d496d..0bdddee6 100644 --- a/routes_common.go +++ b/routes_common.go @@ -166,7 +166,7 @@ func panelUserCheck(w http.ResponseWriter, r *http.Request, user *User) (headerV } } - err = groupCountStmt.QueryRow().Scan(&stats.Groups) + err = stmts.groupCount.QueryRow().Scan(&stats.Groups) if err != nil { return headerVars, stats, InternalError(err, w, r) } @@ -284,7 +284,7 @@ func preRoute(w http.ResponseWriter, r *http.Request) (User, bool) { return *user, false } if host != user.LastIP { - _, err = updateLastIPStmt.Exec(host, user.ID) + _, err = stmts.updateLastIP.Exec(host, user.ID) if err != nil { InternalError(err, w, r) return *user, false @@ -306,3 +306,11 @@ func SuperModOnly(w http.ResponseWriter, r *http.Request, user User) RouteError } return nil } + +// MemberOnly makes sure that only logged in users can access this route +func MemberOnly(w http.ResponseWriter, r *http.Request, user User) RouteError { + if !user.Loggedin { + return NoPermissions(w, r, user) // TODO: Do an error telling them to login instead? + } + return nil +} diff --git a/setting.go b/setting.go index 57b755e2..102c287a 100644 --- a/setting.go +++ b/setting.go @@ -27,7 +27,7 @@ func init() { } func LoadSettings() error { - rows, err := getFullSettingsStmt.Query() + rows, err := stmts.getFullSettings.Query() if err != nil { return err } diff --git a/tasks.go b/tasks.go index 78689df6..f5b95bb4 100644 --- a/tasks.go +++ b/tasks.go @@ -18,7 +18,7 @@ func init() { } func handleExpiredScheduledGroups() error { - rows, err := getExpiredScheduledGroupsStmt.Query() + rows, err := stmts.getExpiredScheduledGroups.Query() if err != nil { return err } @@ -44,7 +44,7 @@ func handleExpiredScheduledGroups() error { func handleServerSync() error { var lastUpdate time.Time - err := getSyncStmt.QueryRow().Scan(&lastUpdate) + err := stmts.getSync.QueryRow().Scan(&lastUpdate) if err != nil { return err } diff --git a/themes.go b/themes.go index 7ead4dff..2b543f2d 100644 --- a/themes.go +++ b/themes.go @@ -77,7 +77,7 @@ func init() { // ? - Delete themes which no longer exist in the themes folder from the database? func LoadThemes() error { changeDefaultThemeMutex.Lock() - rows, err := getThemesStmt.Query() + rows, err := stmts.getThemes.Query() if err != nil { return err } diff --git a/topic.go b/topic.go index db22fcd9..65fc206d 100644 --- a/topic.go +++ b/topic.go @@ -103,7 +103,7 @@ type TopicsRow struct { } func (topic *Topic) Lock() (err error) { - _, err = lockTopicStmt.Exec(topic.ID) + _, err = stmts.lockTopic.Exec(topic.ID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(topic.ID) @@ -112,7 +112,7 @@ func (topic *Topic) Lock() (err error) { } func (topic *Topic) Unlock() (err error) { - _, err = unlockTopicStmt.Exec(topic.ID) + _, err = stmts.unlockTopic.Exec(topic.ID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(topic.ID) @@ -123,7 +123,7 @@ func (topic *Topic) Unlock() (err error) { // TODO: We might want more consistent terminology rather than using stick in some places and pin in others. If you don't understand the difference, there is none, they are one and the same. // ? - We do a CacheDelete() here instead of mutating the pointer to avoid creating a race condition func (topic *Topic) Stick() (err error) { - _, err = stickTopicStmt.Exec(topic.ID) + _, err = stmts.stickTopic.Exec(topic.ID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(topic.ID) @@ -132,7 +132,7 @@ func (topic *Topic) Stick() (err error) { } func (topic *Topic) Unstick() (err error) { - _, err = unstickTopicStmt.Exec(topic.ID) + _, err = stmts.unstickTopic.Exec(topic.ID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(topic.ID) @@ -168,7 +168,7 @@ func (topic *Topic) Delete() error { return err } - _, err = deleteTopicStmt.Exec(topic.ID) + _, err = stmts.deleteTopic.Exec(topic.ID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(topic.ID) @@ -179,7 +179,7 @@ func (topic *Topic) Delete() error { func (topic *Topic) Update(name string, content string) error { content = preparseMessage(content) parsed_content := parseMessage(html.EscapeString(content), topic.ParentID, "forums") - _, err := editTopicStmt.Exec(name, content, parsed_content, topic.ID) + _, err := stmts.editTopic.Exec(name, content, parsed_content, topic.ID) tcache, ok := topics.(TopicCache) if ok { @@ -189,11 +189,11 @@ func (topic *Topic) Update(name string, content string) error { } func (topic *Topic) CreateActionReply(action string, ipaddress string, user User) (err error) { - _, err = createActionReplyStmt.Exec(topic.ID, action, ipaddress, user.ID) + _, err = stmts.createActionReply.Exec(topic.ID, action, ipaddress, user.ID) if err != nil { return err } - _, err = addRepliesToTopicStmt.Exec(1, user.ID, topic.ID) + _, err = stmts.addRepliesToTopic.Exec(1, user.ID, topic.ID) tcache, ok := topics.(TopicCache) if ok { tcache.CacheRemove(topic.ID) @@ -235,7 +235,7 @@ func getTopicUser(tid int) (TopicUser, error) { } tu := TopicUser{ID: tid} - err := getTopicUserStmt.QueryRow(tid).Scan(&tu.Title, &tu.Content, &tu.CreatedBy, &tu.CreatedAt, &tu.IsClosed, &tu.Sticky, &tu.ParentID, &tu.IPAddress, &tu.PostCount, &tu.LikeCount, &tu.CreatedByName, &tu.Avatar, &tu.Group, &tu.URLPrefix, &tu.URLName, &tu.Level) + err := stmts.getTopicUser.QueryRow(tid).Scan(&tu.Title, &tu.Content, &tu.CreatedBy, &tu.CreatedAt, &tu.IsClosed, &tu.Sticky, &tu.ParentID, &tu.IPAddress, &tu.PostCount, &tu.LikeCount, &tu.CreatedByName, &tu.Avatar, &tu.Group, &tu.URLPrefix, &tu.URLName, &tu.Level) tu.Link = buildTopicURL(nameToSlug(tu.Title), tu.ID) tu.UserLink = buildProfileURL(nameToSlug(tu.CreatedByName), tu.CreatedBy) tu.Tag = gstore.DirtyGet(tu.Group).Tag @@ -282,7 +282,7 @@ func getDummyTopic() *Topic { func getTopicByReply(rid int) (*Topic, error) { topic := Topic{ID: 0} - err := getTopicByReplyStmt.QueryRow(rid).Scan(&topic.ID, &topic.Title, &topic.Content, &topic.CreatedBy, &topic.CreatedAt, &topic.IsClosed, &topic.Sticky, &topic.ParentID, &topic.IPAddress, &topic.PostCount, &topic.LikeCount, &topic.Data) + err := stmts.getTopicByReply.QueryRow(rid).Scan(&topic.ID, &topic.Title, &topic.Content, &topic.CreatedBy, &topic.CreatedAt, &topic.IsClosed, &topic.Sticky, &topic.ParentID, &topic.IPAddress, &topic.PostCount, &topic.LikeCount, &topic.Data) topic.Link = buildTopicURL(nameToSlug(topic.Title), topic.ID) return &topic, err } diff --git a/topic_store.go b/topic_store.go index ecb3df9e..80a139af 100644 --- a/topic_store.go +++ b/topic_store.go @@ -157,7 +157,7 @@ func (mts *MemoryTopicStore) Create(fid int, topicName string, content string, u wcount := wordCount(content) // TODO: Move this statement into the topic store - res, err := createTopicStmt.Exec(fid, topicName, content, parsedContent, uid, ipaddress, wcount, uid) + res, err := stmts.createTopic.Exec(fid, topicName, content, parsedContent, uid, ipaddress, wcount, uid) if err != nil { return 0, err } @@ -319,7 +319,7 @@ func (sts *SQLTopicStore) Create(fid int, topicName string, content string, uid wcount := wordCount(content) // TODO: Move this statement into the topic store - res, err := createTopicStmt.Exec(fid, topicName, content, parsedContent, uid, ipaddress, wcount, uid) + res, err := stmts.createTopic.Exec(fid, topicName, content, parsedContent, uid, ipaddress, wcount, uid) if err != nil { return 0, err } diff --git a/user.go b/user.go index 2892a4e6..d5390e0b 100644 --- a/user.go +++ b/user.go @@ -174,11 +174,11 @@ func (user *User) RevertGroupUpdate() error { // TODO: Use a transaction here // ? - Add a Deactivate method? Not really needed, if someone's been bad you could do a ban, I guess it might be useful, if someone says that email x isn't actually owned by the user in question? func (user *User) Activate() (err error) { - _, err = activateUserStmt.Exec(user.ID) + _, err = stmts.activateUser.Exec(user.ID) if err != nil { return err } - _, err = changeGroupStmt.Exec(config.DefaultGroup, user.ID) + _, err = stmts.changeGroup.Exec(config.DefaultGroup, user.ID) ucache, ok := users.(UserCache) if ok { ucache.CacheRemove(user.ID) @@ -190,7 +190,7 @@ func (user *User) Activate() (err error) { // TODO: Delete this user's content too? // TODO: Expose this to the admin? func (user *User) Delete() error { - _, err := deleteUserStmt.Exec(user.ID) + _, err := stmts.deleteUser.Exec(user.ID) if err != nil { return err } @@ -202,7 +202,7 @@ func (user *User) Delete() error { } func (user *User) ChangeName(username string) (err error) { - _, err = setUsernameStmt.Exec(username, user.ID) + _, err = stmts.setUsername.Exec(username, user.ID) ucache, ok := users.(UserCache) if ok { ucache.CacheRemove(user.ID) @@ -211,7 +211,7 @@ func (user *User) ChangeName(username string) (err error) { } func (user *User) ChangeAvatar(avatar string) (err error) { - _, err = setAvatarStmt.Exec(avatar, user.ID) + _, err = stmts.setAvatar.Exec(avatar, user.ID) ucache, ok := users.(UserCache) if ok { ucache.CacheRemove(user.ID) @@ -220,7 +220,7 @@ func (user *User) ChangeAvatar(avatar string) (err error) { } func (user *User) ChangeGroup(group int) (err error) { - _, err = updateUserGroupStmt.Exec(group, user.ID) + _, err = stmts.updateUserGroup.Exec(group, user.ID) ucache, ok := users.(UserCache) if ok { ucache.CacheRemove(user.ID) @@ -232,7 +232,7 @@ func (user *User) increasePostStats(wcount int, topic bool) (err error) { var mod int baseScore := 1 if topic { - _, err = incrementUserTopicsStmt.Exec(1, user.ID) + _, err = stmts.incrementUserTopics.Exec(1, user.ID) if err != nil { return err } @@ -241,26 +241,26 @@ func (user *User) increasePostStats(wcount int, topic bool) (err error) { settings := settingBox.Load().(SettingBox) if wcount >= settings["megapost_min_words"].(int) { - _, err = incrementUserMegapostsStmt.Exec(1, 1, 1, user.ID) + _, err = stmts.incrementUserMegaposts.Exec(1, 1, 1, user.ID) mod = 4 } else if wcount >= settings["bigpost_min_words"].(int) { - _, err = incrementUserBigpostsStmt.Exec(1, 1, user.ID) + _, err = stmts.incrementUserBigposts.Exec(1, 1, user.ID) mod = 1 } else { - _, err = incrementUserPostsStmt.Exec(1, user.ID) + _, err = stmts.incrementUserPosts.Exec(1, user.ID) } if err != nil { return err } - _, err = incrementUserScoreStmt.Exec(baseScore+mod, user.ID) + _, err = stmts.incrementUserScore.Exec(baseScore+mod, user.ID) if err != nil { return err } //log.Print(user.Score + base_score + mod) //log.Print(getLevel(user.Score + base_score + mod)) // TODO: Use a transaction to prevent level desyncs? - _, err = updateUserLevelStmt.Exec(getLevel(user.Score+baseScore+mod), user.ID) + _, err = stmts.updateUserLevel.Exec(getLevel(user.Score+baseScore+mod), user.ID) return err } @@ -268,7 +268,7 @@ func (user *User) decreasePostStats(wcount int, topic bool) (err error) { var mod int baseScore := -1 if topic { - _, err = incrementUserTopicsStmt.Exec(-1, user.ID) + _, err = stmts.incrementUserTopics.Exec(-1, user.ID) if err != nil { return err } @@ -277,24 +277,24 @@ func (user *User) decreasePostStats(wcount int, topic bool) (err error) { settings := settingBox.Load().(SettingBox) if wcount >= settings["megapost_min_words"].(int) { - _, err = incrementUserMegapostsStmt.Exec(-1, -1, -1, user.ID) + _, err = stmts.incrementUserMegaposts.Exec(-1, -1, -1, user.ID) mod = 4 } else if wcount >= settings["bigpost_min_words"].(int) { - _, err = incrementUserBigpostsStmt.Exec(-1, -1, user.ID) + _, err = stmts.incrementUserBigposts.Exec(-1, -1, user.ID) mod = 1 } else { - _, err = incrementUserPostsStmt.Exec(-1, user.ID) + _, err = stmts.incrementUserPosts.Exec(-1, user.ID) } if err != nil { return err } - _, err = incrementUserScoreStmt.Exec(baseScore-mod, user.ID) + _, err = stmts.incrementUserScore.Exec(baseScore-mod, user.ID) if err != nil { return err } // TODO: Use a transaction to prevent level desyncs? - _, err = updateUserLevelStmt.Exec(getLevel(user.Score-baseScore-mod), user.ID) + _, err = stmts.updateUserLevel.Exec(getLevel(user.Score-baseScore-mod), user.ID) return err } @@ -359,7 +359,7 @@ func SetPassword(uid int, password string) error { if err != nil { return err } - _, err = setPasswordStmt.Exec(hashedPassword, salt, uid) + _, err = stmts.setPassword.Exec(hashedPassword, salt, uid) return err } diff --git a/utils.go b/utils.go index 034ba80b..f79c4041 100644 --- a/utils.go +++ b/utils.go @@ -423,12 +423,14 @@ func buildSlug(slug string, id int) string { return slug + "." + strconv.Itoa(id) } +// TODO: Make a store for this? func addModLog(action string, elementID int, elementType string, ipaddress string, actorID int) (err error) { - _, err = addModlogEntryStmt.Exec(action, elementID, elementType, ipaddress, actorID) + _, err = stmts.addModlogEntry.Exec(action, elementID, elementType, ipaddress, actorID) return err } +// TODO: Make a store for this? func addAdminLog(action string, elementID string, elementType int, ipaddress string, actorID int) (err error) { - _, err = addAdminlogEntryStmt.Exec(action, elementID, elementType, ipaddress, actorID) + _, err = stmts.addAdminlogEntry.Exec(action, elementID, elementType, ipaddress, actorID) return err } diff --git a/widgets.go b/widgets.go index 26406095..ce00ee67 100644 --- a/widgets.go +++ b/widgets.go @@ -40,8 +40,9 @@ type NameTextPair struct { Text string } +// TODO: Make a store for this? func initWidgets() error { - rows, err := getWidgetsStmt.Query() + rows, err := stmts.getWidgets.Query() if err != nil { return err } diff --git a/word_filters.go b/word_filters.go index 53ba7d6c..338a0e85 100644 --- a/word_filters.go +++ b/word_filters.go @@ -16,7 +16,7 @@ func init() { } func LoadWordFilters() error { - rows, err := getWordFiltersStmt.Query() + rows, err := stmts.getWordFilters.Query() if err != nil { return err }