2017-06-05 11:57:27 +00:00
/* WIP Under Construction */
2017-06-13 07:12:58 +00:00
package qgen
2017-06-05 11:57:27 +00:00
2018-01-21 11:17:43 +00:00
import (
2022-02-21 03:32:53 +00:00
"database/sql"
"errors"
2020-03-05 01:01:23 +00:00
2022-02-21 03:32:53 +00:00
//"fmt"
"os"
"runtime"
"strconv"
"strings"
2018-03-31 05:25:27 +00:00
2022-02-21 03:32:53 +00:00
_ "github.com/go-sql-driver/mysql"
2018-01-21 11:17:43 +00:00
)
2017-06-05 11:57:27 +00:00
2018-03-31 05:25:27 +00:00
var ErrNoCollation = errors . New ( "You didn't provide a collation" )
2017-06-05 11:57:27 +00:00
func init ( ) {
2022-02-21 03:32:53 +00:00
Registry = append ( Registry ,
& MysqlAdapter { Name : "mysql" , Buffer : make ( map [ string ] DBStmt ) } ,
)
2017-06-05 11:57:27 +00:00
}
2017-10-30 09:57:08 +00:00
type MysqlAdapter struct {
2022-02-21 03:32:53 +00:00
Name string // ? - Do we really need this? Can't we hard-code this?
Buffer map [ string ] DBStmt
BufferOrder [ ] string // Map iteration order is random, so we need this to track the order, so we don't get huge diffs every commit
2017-06-05 11:57:27 +00:00
}
Added Quick Topic.
Added Attachments.
Added Attachment Media Embeds.
Renamed a load of *Store and *Cache methods to reduce the amount of unneccesary typing.
Added petabytes as a unit and cleaned up a few of the friendly units.
Refactored the username change logic to make it easier to maintain.
Refactored the avatar change logic to make it easier to maintain.
Shadow now uses CSS Variables for most of it's colours. We have plans to transpile this to support older browsers later on!
Snuck some CSS Variables into Tempra Conflux.
Added the GroupCache interface to MemoryGroupStore.
Added the Length method to MemoryGroupStore.
Added support for a site short name.
Added the UploadFiles permission.
Renamed more functions.
Fixed the background for the left gutter on the postbit for Tempra Simple and Shadow.
Added support for if statements operating on int8, int16, int32, int32, int64, uint, uint8, uint16, uint32, uint64, float32, and float64 for the template compiler.
Added support for if statements operating on slices and maps for the template compiler.
Fixed a security exploit in reply editing.
Fixed a bug in the URL detector in the parser where it couldn't find URLs with non-standard ports.
Fixed buttons having blue outlines on focus on Shadow.
Refactored the topic creation logic to make it easier to maintain.
Made a few responsive fixes, but there's still more to do in the following commits!
2017-10-05 10:20:28 +00:00
// GetName gives you the name of the database adapter. In this case, it's mysql
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) GetName ( ) string {
2022-02-21 03:32:53 +00:00
return a . Name
2017-06-05 11:57:27 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) GetStmt ( name string ) DBStmt {
2022-02-21 03:32:53 +00:00
return a . Buffer [ name ]
2017-06-13 07:12:58 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) GetStmts ( ) map [ string ] DBStmt {
2022-02-21 03:32:53 +00:00
return a . Buffer
2017-06-13 07:12:58 +00:00
}
2018-08-29 01:37:57 +00:00
// TODO: Add an option to disable unix pipes
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) BuildConn ( config map [ string ] string ) ( * sql . DB , error ) {
2022-02-21 03:32:53 +00:00
dbCollation , ok := config [ "collation" ]
if ! ok {
return nil , ErrNoCollation
}
var dbpassword string
if config [ "password" ] != "" {
dbpassword = ":" + config [ "password" ]
}
// First try opening a pipe as those are faster
if runtime . GOOS == "linux" {
dbsocket := "/tmp/mysql.sock"
if config [ "socket" ] != "" {
dbsocket = config [ "socket" ]
}
// The MySQL adapter refuses to open any other connections, if the unix socket doesn't exist, so check for it first
_ , err := os . Stat ( dbsocket )
if err == nil {
db , err := sql . Open ( "mysql" , config [ "username" ] + dbpassword + "@unix(" + dbsocket + ")/" + config [ "name" ] + "?collation=" + dbCollation + "&parseTime=true" )
if err == nil {
// Make sure that the connection is alive
return db , db . Ping ( )
}
}
}
// Open the database connection
db , err := sql . Open ( "mysql" , config [ "username" ] + dbpassword + "@tcp(" + config [ "host" ] + ":" + config [ "port" ] + ")/" + config [ "name" ] + "?collation=" + dbCollation + "&parseTime=true" )
if err != nil {
return db , err
}
// Make sure that the connection is alive
return db , db . Ping ( )
2018-03-31 05:25:27 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) DbVersion ( ) string {
2022-02-21 03:32:53 +00:00
return "SELECT VERSION()"
2018-03-31 05:25:27 +00:00
}
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) DropTable ( name , table string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
q := "DROP TABLE IF EXISTS `" + table + "`;"
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "drop-table" , q )
return q , nil
2018-05-11 05:41:51 +00:00
}
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) CreateTable ( name , table , charset , collation string , cols [ ] DBTableColumn , keys [ ] DBTableKey ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if len ( cols ) == 0 {
return "" , errors . New ( "You can't have a table with no columns" )
}
var qsb strings . Builder
//q := "CREATE TABLE `" + table + "`("
w := func ( s string ) {
qsb . WriteString ( s )
}
w ( "CREATE TABLE `" )
w ( table )
w ( "`(" )
for i , col := range cols {
if i != 0 {
w ( ",\n\t`" )
} else {
w ( "\n\t`" )
}
col , size , end := a . parseColumn ( col )
//q += "\n\t`" + col.Name + "` " + col.Type + size + end + ","
w ( col . Name )
w ( "` " )
w ( col . Type )
w ( size )
w ( end )
}
if len ( keys ) > 0 {
/ * if len ( cols ) > 0 {
w ( "," )
} * /
for _ , k := range keys {
/ * if ii != 0 {
w ( ",\n\t" )
} else {
w ( "\n\t" )
} * /
w ( ",\n\t" )
//q += "\n\t" + key.Type
w ( k . Type )
if k . Type != "unique" {
//q += " key"
w ( " key" )
}
if k . Type == "foreign" {
cols := strings . Split ( k . Columns , "," )
//q += "(`" + cols[0] + "`) REFERENCES `" + k.FTable + "`(`" + cols[1] + "`)"
w ( "(`" )
w ( cols [ 0 ] )
w ( "`) REFERENCES `" )
w ( k . FTable )
w ( "`(`" )
w ( cols [ 1 ] )
w ( "`)" )
if k . Cascade {
//q += " ON DELETE CASCADE"
w ( " ON DELETE CASCADE" )
}
//q += ","
} else {
//q += "("
w ( "(" )
for i , col := range strings . Split ( k . Columns , "," ) {
/ * if i != 0 {
q += ",`" + col + "`"
} else {
q += "`" + col + "`"
} * /
if i != 0 {
w ( ",`" )
} else {
w ( "`" )
}
w ( col )
w ( "`" )
}
//q += "),"
w ( ")" )
}
}
}
//q = q[0:len(q)-1] + "\n)"
w ( "\n)" )
if charset != "" {
//q += " CHARSET=" + charset
w ( " CHARSET=" )
w ( charset )
}
if collation != "" {
//q += " COLLATE " + collation
w ( " COLLATE " )
w ( collation )
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
//q += ";"
w ( ";" )
q := qsb . String ( )
a . pushStatement ( name , "create-table" , q )
return q , nil
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func ( a * MysqlAdapter ) DropColumn ( name , table , colName string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
q := "ALTER TABLE `" + table + "` DROP COLUMN `" + colName + "`;"
a . pushStatement ( name , "drop-column" , q )
return q , nil
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
// ! Currently broken in MariaDB. Planned.
func ( a * MysqlAdapter ) RenameColumn ( name , table , oldName , newName string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
q := "ALTER TABLE `" + table + "` RENAME COLUMN `" + oldName + "` TO `" + newName + "`;"
a . pushStatement ( name , "rename-column" , q )
return q , nil
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
func ( a * MysqlAdapter ) ChangeColumn ( name , table , colName string , col DBTableColumn ) ( string , error ) {
2022-02-21 03:32:53 +00:00
col . Default = ""
col , size , end := a . parseColumn ( col )
q := "ALTER TABLE `" + table + "` CHANGE COLUMN `" + colName + "` `" + col . Name + "` " + col . Type + size + end
a . pushStatement ( name , "change-column" , q )
return q , nil
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
func ( a * MysqlAdapter ) SetDefaultColumn ( name , table , colName , colType , defaultStr string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if defaultStr == "" {
defaultStr = "''"
}
// TODO: Exclude the other variants of text like mediumtext and longtext too
expr := ""
/ * if colType == "datetime" && defaultStr [ len ( defaultStr ) - 1 ] == ')' {
end += defaultStr
} else * / if a . stringyType ( colType ) && defaultStr != "''" {
expr += "'" + defaultStr + "'"
} else {
expr += defaultStr
}
q := "ALTER TABLE `" + table + "` ALTER COLUMN `" + colName + "` SET DEFAULT " + expr + ";"
a . pushStatement ( name , "set-default-column" , q )
return q , nil
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
}
func ( a * MysqlAdapter ) parseColumn ( col DBTableColumn ) ( ocol DBTableColumn , size , end string ) {
2022-02-21 03:32:53 +00:00
// Make it easier to support Cassandra in the future
if col . Type == "createdAt" {
col . Type = "datetime"
// MySQL doesn't support this x.x
/ * if col . Default == "" {
col . Default = "UTC_TIMESTAMP()"
} * /
} else if col . Type == "json" {
col . Type = "text"
}
if col . Size > 0 {
size = "(" + strconv . Itoa ( col . Size ) + ")"
}
// TODO: Exclude the other variants of text like mediumtext and longtext too
if col . Default != "" && col . Type != "text" {
end = " DEFAULT "
/ * if col . Type == "datetime" && col . Default [ len ( col . Default ) - 1 ] == ')' {
end += column . Default
} else * / if a . stringyType ( col . Type ) && col . Default != "''" {
end += "'" + col . Default + "'"
} else {
end += col . Default
}
}
if col . Null {
end += " null"
} else {
end += " not null"
}
if col . AutoIncrement {
end += " AUTO_INCREMENT"
}
return col , size , end
2018-05-27 09:36:35 +00:00
}
// TODO: Support AFTER column
// TODO: Test to make sure everything works here
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func ( a * MysqlAdapter ) AddColumn ( name , table string , col DBTableColumn , key * DBTableKey ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
col , size , end := a . parseColumn ( col )
q := "ALTER TABLE `" + table + "` ADD COLUMN " + "`" + col . Name + "` " + col . Type + size + end
if key != nil {
q += " " + key . Type
if key . Type != "unique" {
q += " key"
} else if key . Type == "primary" {
q += " first"
}
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "add-column" , q )
return q , nil
2018-05-27 09:36:35 +00:00
}
2018-12-31 09:03:49 +00:00
// TODO: Test to make sure everything works here
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) AddIndex ( name , table , iname , colname string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if iname == "" {
return "" , errors . New ( "You need a name for the index" )
}
if colname == "" {
return "" , errors . New ( "You need a name for the column" )
}
q := "ALTER TABLE `" + table + "` ADD INDEX " + "`i_" + iname + "` (`" + colname + "`);"
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "add-index" , q )
return q , nil
2018-12-31 09:03:49 +00:00
}
2019-02-23 06:29:19 +00:00
// TODO: Test to make sure everything works here
// Only supports FULLTEXT right now
2020-02-24 11:15:17 +00:00
func ( a * MysqlAdapter ) AddKey ( name , table , cols string , key DBTableKey ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if cols == "" {
return "" , errors . New ( "You need to specify columns" )
}
var colstr string
for _ , col := range strings . Split ( cols , "," ) {
colstr += "`" + col + "`,"
}
if len ( colstr ) > 1 {
colstr = colstr [ : len ( colstr ) - 1 ]
}
var q string
if key . Type == "fulltext" {
q = "ALTER TABLE `" + table + "` ADD FULLTEXT(" + colstr + ")"
} else {
return "" , errors . New ( "Only fulltext is supported by AddKey right now" )
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "add-key" , q )
return q , nil
2019-05-06 04:04:00 +00:00
}
2020-02-20 23:55:45 +00:00
func ( a * MysqlAdapter ) RemoveIndex ( name , table , iname string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if iname == "" {
return "" , errors . New ( "You need a name for the index" )
}
q := "ALTER TABLE `" + table + "` DROP INDEX `" + iname + "`"
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "remove-index" , q )
return q , nil
2020-02-20 23:55:45 +00:00
}
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) AddForeignKey ( name , table , col , ftable , fcolumn string , cascade bool ) ( out string , e error ) {
2022-02-21 03:32:53 +00:00
c := func ( str string , val bool ) {
if e != nil || ! val {
return
}
e = errors . New ( "You need a " + str + " for this table" )
}
c ( "name" , table == "" )
c ( "col" , col == "" )
c ( "ftable" , ftable == "" )
c ( "fcolumn" , fcolumn == "" )
if e != nil {
return "" , e
}
q := "ALTER TABLE `" + table + "` ADD CONSTRAINT `fk_" + col + "` FOREIGN KEY(`" + col + "`) REFERENCES `" + ftable + "`(`" + fcolumn + "`)"
if cascade {
q += " ON DELETE CASCADE"
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "add-foreign-key" , q )
return q , nil
2019-02-23 06:29:19 +00:00
}
2021-04-29 22:33:02 +00:00
const silen1 = len ( "INSERT INTO``()VALUES() " )
2019-12-31 21:57:54 +00:00
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) SimpleInsert ( name , table , cols , fields string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . Grow ( silen1 + len ( table ) )
sb . WriteString ( "INSERT INTO`" )
sb . WriteString ( table )
if cols != "" {
sb . WriteString ( "`(" )
sb . WriteString ( a . buildColumns ( cols ) )
sb . WriteString ( ")VALUES(" )
fs := processFields ( fields )
sb . Grow ( len ( fs ) * 3 )
for i , field := range fs {
if i != 0 {
sb . WriteString ( "," )
}
nameLen := len ( field . Name )
if field . Name [ 0 ] == '"' && field . Name [ nameLen - 1 ] == '"' && nameLen >= 3 {
sb . WriteRune ( '\'' )
sb . WriteString ( field . Name [ 1 : nameLen - 1 ] )
sb . WriteRune ( '\'' )
} else if field . Name [ 0 ] == '\'' && field . Name [ nameLen - 1 ] == '\'' && nameLen >= 3 {
sb . WriteRune ( '\'' )
sb . WriteString ( strings . Replace ( field . Name [ 1 : nameLen - 1 ] , "'" , "''" , - 1 ) )
sb . WriteRune ( '\'' )
} else {
sb . WriteString ( field . Name )
}
}
sb . WriteString ( ")" )
} else {
sb . WriteString ( "`()VALUES()" )
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
q := sb . String ( )
queryStrPool . Put ( sb )
a . pushStatement ( name , "insert" , q )
return q , nil
2017-06-05 11:57:27 +00:00
}
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) SimpleBulkInsert ( name , table , cols string , fieldSet [ ] string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . Grow ( silen1 + len ( table ) )
sb . WriteString ( "INSERT INTO`" )
sb . WriteString ( table )
if cols != "" {
sb . WriteString ( "`(" )
sb . WriteString ( a . buildColumns ( cols ) )
sb . WriteString ( ")VALUES(" )
for oi , fields := range fieldSet {
if oi != 0 {
sb . WriteString ( ",(" )
}
fs := processFields ( fields )
sb . Grow ( len ( fs ) * 3 )
for i , field := range fs {
if i != 0 {
sb . WriteString ( "," )
}
nameLen := len ( field . Name )
if field . Name [ 0 ] == '"' && field . Name [ nameLen - 1 ] == '"' && nameLen >= 3 {
//field.Name = "'" + field.Name[1:nameLen-1] + "'"
sb . WriteString ( "'" )
sb . WriteString ( field . Name [ 1 : nameLen - 1 ] )
sb . WriteString ( "'" )
continue
}
if field . Name [ 0 ] == '\'' && field . Name [ nameLen - 1 ] == '\'' && nameLen >= 3 {
//field.Name = "'" + strings.Replace(field.Name[1:nameLen-1], "'", "''", -1) + "'"
sb . WriteString ( "'" )
sb . WriteString ( strings . Replace ( field . Name [ 1 : nameLen - 1 ] , "'" , "''" , - 1 ) )
sb . WriteString ( "'" )
continue
}
sb . WriteString ( field . Name )
}
sb . WriteString ( ")" )
}
} else {
sb . WriteString ( "`()VALUES()" )
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
q := sb . String ( )
queryStrPool . Put ( sb )
a . pushStatement ( name , "bulk-insert" , q )
return q , nil
2020-02-24 11:15:17 +00:00
}
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) buildColumns ( cols string ) string {
2022-02-21 03:32:53 +00:00
if cols == "" {
return ""
}
// Escape the column names, just in case we've used a reserved keyword
var cb strings . Builder
pcols := processColumns ( cols )
var n int
for i , col := range pcols {
if i != 0 {
n += 1
}
if col . Type == TokenFunc {
n += len ( col . Left )
} else {
n += len ( col . Left ) + 2
}
}
cb . Grow ( n )
for i , col := range pcols {
if col . Type == TokenFunc {
if i != 0 {
cb . WriteString ( "," )
}
//q += col.Left + ","
cb . WriteString ( col . Left )
} else {
//q += "`" + col.Left + "`,"
if i != 0 {
cb . WriteString ( ",`" )
} else {
cb . WriteString ( "`" )
}
cb . WriteString ( col . Left )
cb . WriteString ( "`" )
}
}
return cb . String ( )
2017-11-05 01:04:57 +00:00
}
2017-10-16 07:32:58 +00:00
// ! DEPRECATED
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) SimpleReplace ( name , table , cols , fields string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if len ( cols ) == 0 {
return "" , errors . New ( "No columns found for SimpleInsert" )
}
if len ( fields ) == 0 {
return "" , errors . New ( "No input data found for SimpleInsert" )
}
q := "REPLACE INTO `" + table + "`(" + a . buildColumns ( cols ) + ") VALUES ("
for _ , field := range processFields ( fields ) {
q += field . Name + ","
}
q = q [ 0 : len ( q ) - 1 ] + ")"
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "replace" , q )
return q , nil
2017-06-10 07:58:15 +00:00
}
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleUpsert ( name , table , columns , fields , where string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if len ( columns ) == 0 {
return "" , errors . New ( "No columns found for SimpleInsert" )
}
if len ( fields ) == 0 {
return "" , errors . New ( "No input data found for SimpleInsert" )
}
if where == "" {
return "" , errors . New ( "You need a where for this upsert" )
}
q := "INSERT INTO `" + table + "`("
parsedFields := processFields ( fields )
var insertColumns , insertValues string
setBit := ") ON DUPLICATE KEY UPDATE "
for columnID , col := range processColumns ( columns ) {
field := parsedFields [ columnID ]
if col . Type == TokenFunc {
insertColumns += col . Left + ","
insertValues += field . Name + ","
setBit += col . Left + " = " + field . Name + " AND "
} else {
insertColumns += "`" + col . Left + "`,"
insertValues += field . Name + ","
setBit += "`" + col . Left + "` = " + field . Name + " AND "
}
}
insertColumns = insertColumns [ 0 : len ( insertColumns ) - 1 ]
insertValues = insertValues [ 0 : len ( insertValues ) - 1 ]
insertColumns += ") VALUES (" + insertValues
setBit = setBit [ 0 : len ( setBit ) - 5 ]
q += insertColumns + setBit
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "upsert" , q )
return q , nil
2017-10-16 07:32:58 +00:00
}
2020-04-20 23:39:35 +00:00
const sulen1 = len ( "UPDATE `` SET " )
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) SimpleUpdate ( up * updatePrebuilder ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if up . table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if up . set == "" {
return "" , errors . New ( "You need to set data in this update statement" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . Grow ( sulen1 + len ( up . table ) )
sb . WriteString ( "UPDATE `" )
sb . WriteString ( up . table )
sb . WriteString ( "` SET " )
set := processSet ( up . set )
sb . Grow ( len ( set ) * 6 )
for i , item := range set {
if i != 0 {
sb . WriteString ( ",`" )
} else {
sb . WriteString ( "`" )
}
sb . WriteString ( item . Column )
sb . WriteString ( "`=" )
for _ , token := range item . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr :
sb . WriteString ( " " )
sb . WriteString ( token . Contents )
case TokenColumn :
sb . WriteString ( " `" )
sb . WriteString ( token . Contents )
sb . WriteString ( "`" )
case TokenString :
sb . WriteString ( " '" )
sb . WriteString ( token . Contents )
sb . WriteString ( "'" )
}
}
}
e := a . buildFlexiWhereSb ( sb , up . where , up . dateCutoff )
if e != nil {
return sb . String ( ) , e
}
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
q := sb . String ( )
queryStrPool . Put ( sb )
a . pushStatement ( up . name , "update" , q )
return q , nil
2017-06-05 11:57:27 +00:00
}
2020-04-20 23:39:35 +00:00
const sdlen1 = len ( "DELETE FROM `` WHERE" )
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleDelete ( name , table , where string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if where == "" {
return "" , errors . New ( "You need to specify what data you want to delete" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . Grow ( sdlen1 + len ( table ) )
sb . WriteString ( "DELETE FROM `" )
sb . WriteString ( table )
sb . WriteString ( "` WHERE" )
// Add support for BETWEEN x.x
for i , loc := range processWhere ( where ) {
if i != 0 {
sb . WriteString ( " AND" )
}
for _ , token := range loc . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot :
sb . WriteRune ( ' ' )
sb . WriteString ( token . Contents )
case TokenColumn :
sb . WriteString ( " `" )
sb . WriteString ( token . Contents )
sb . WriteRune ( '`' )
case TokenString :
sb . WriteString ( " '" )
sb . WriteString ( token . Contents )
sb . WriteRune ( '\'' )
default :
panic ( "This token doesn't exist o_o" )
}
}
}
q := strings . TrimSpace ( sb . String ( ) )
queryStrPool . Put ( sb )
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( name , "delete" , q )
return q , nil
2019-06-05 04:57:10 +00:00
}
2020-04-20 23:39:35 +00:00
const cdlen1 = len ( "DELETE FROM ``" )
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) ComplexDelete ( b * deletePrebuilder ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if b . table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if b . where == "" && b . dateCutoff == nil {
return "" , errors . New ( "You need to specify what data you want to delete" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . Grow ( cdlen1 + len ( b . table ) )
sb . WriteString ( "DELETE FROM `" )
sb . WriteString ( b . table )
sb . WriteRune ( '`' )
e := a . buildFlexiWhereSb ( sb , b . where , b . dateCutoff )
if e != nil {
return sb . String ( ) , e
}
q := sb . String ( )
queryStrPool . Put ( sb )
// TODO: Shunt the table name logic and associated stmt list up to the a higher layer to reduce the amount of unnecessary overhead in the builder / accumulator
a . pushStatement ( b . name , "delete" , q )
return q , nil
2017-06-12 09:03:14 +00:00
}
2017-10-30 09:57:08 +00:00
// We don't want to accidentally wipe tables, so we'll have a separate method for purging tables instead
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) Purge ( name , table string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
q := "DELETE FROM `" + table + "`"
a . pushStatement ( name , "purge" , q )
return q , nil
2017-06-12 09:03:14 +00:00
}
2020-01-01 08:53:48 +00:00
func ( a * MysqlAdapter ) buildWhere ( where string , sb * strings . Builder ) error {
2022-02-21 03:32:53 +00:00
if len ( where ) == 0 {
return nil
}
spl := processWhere ( where )
sb . Grow ( len ( spl ) * 8 )
for i , loc := range spl {
if i != 0 {
sb . WriteString ( " AND " )
} else {
sb . WriteString ( " WHERE " )
}
for _ , token := range loc . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
sb . WriteString ( token . Contents )
sb . WriteRune ( ' ' )
case TokenColumn :
sb . WriteRune ( '`' )
sb . WriteString ( token . Contents )
sb . WriteRune ( '`' )
case TokenString :
sb . WriteRune ( '\'' )
sb . WriteString ( token . Contents )
sb . WriteRune ( '\'' )
default :
return errors . New ( "This token doesn't exist o_o" )
}
}
}
return nil
2018-01-03 07:46:18 +00:00
}
// The new version of buildWhere() currently only used in ComplexSelect for complex OO builder queries
2020-04-20 23:39:35 +00:00
const FlexiHint1 = len ( ` <UTC_TIMESTAMP()-interval ? ` )
2020-03-04 23:56:45 +00:00
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildFlexiWhere ( where string , dateCutoff * dateCutoff ) ( q string , err error ) {
2022-02-21 03:32:53 +00:00
if len ( where ) == 0 && dateCutoff == nil {
return "" , nil
}
var sb strings . Builder
sb . WriteString ( " WHERE" )
if dateCutoff != nil {
sb . Grow ( 6 + FlexiHint1 )
sb . WriteRune ( ' ' )
sb . WriteString ( dateCutoff . Column )
switch dateCutoff . Type {
case 0 :
sb . WriteString ( " BETWEEN (UTC_TIMESTAMP()-interval " )
sb . WriteString ( strconv . Itoa ( dateCutoff . Quantity ) )
sb . WriteString ( " " )
sb . WriteString ( dateCutoff . Unit )
sb . WriteString ( ") AND UTC_TIMESTAMP()" )
case 11 :
sb . WriteString ( "<UTC_TIMESTAMP()-interval ? " )
sb . WriteString ( dateCutoff . Unit )
default :
sb . WriteString ( "<UTC_TIMESTAMP()-interval " )
sb . WriteString ( strconv . Itoa ( dateCutoff . Quantity ) )
sb . WriteRune ( ' ' )
sb . WriteString ( dateCutoff . Unit )
}
}
if dateCutoff != nil && len ( where ) != 0 {
sb . WriteString ( " AND" )
}
if len ( where ) != 0 {
wh := processWhere ( where )
sb . Grow ( ( len ( wh ) * 8 ) - 5 )
for i , loc := range wh {
if i != 0 {
sb . WriteString ( " AND " )
}
for _ , token := range loc . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
sb . WriteString ( " " )
sb . WriteString ( token . Contents )
case TokenColumn :
sb . WriteString ( " `" )
sb . WriteString ( token . Contents )
sb . WriteString ( "`" )
case TokenString :
sb . WriteString ( " '" )
sb . WriteString ( token . Contents )
sb . WriteString ( "'" )
default :
return sb . String ( ) , errors . New ( "This token doesn't exist o_o" )
}
}
}
}
return sb . String ( ) , nil
2017-11-05 01:04:57 +00:00
}
2017-09-03 04:50:31 +00:00
2020-04-20 23:39:35 +00:00
func ( a * MysqlAdapter ) buildFlexiWhereSb ( sb * strings . Builder , where string , dateCutoff * dateCutoff ) ( err error ) {
2022-02-21 03:32:53 +00:00
if len ( where ) == 0 && dateCutoff == nil {
return nil
}
sb . WriteString ( " WHERE" )
if dateCutoff != nil {
sb . Grow ( 6 + FlexiHint1 )
sb . WriteRune ( ' ' )
sb . WriteString ( dateCutoff . Column )
switch dateCutoff . Type {
case 0 :
sb . WriteString ( " BETWEEN (UTC_TIMESTAMP()-interval " )
sb . WriteString ( strconv . Itoa ( dateCutoff . Quantity ) )
sb . WriteString ( " " )
sb . WriteString ( dateCutoff . Unit )
sb . WriteString ( ") AND UTC_TIMESTAMP()" )
case 11 :
sb . WriteString ( "<UTC_TIMESTAMP()-interval ? " )
sb . WriteString ( dateCutoff . Unit )
default :
sb . WriteString ( "<UTC_TIMESTAMP()-interval " )
sb . WriteString ( strconv . Itoa ( dateCutoff . Quantity ) )
sb . WriteRune ( ' ' )
sb . WriteString ( dateCutoff . Unit )
}
}
if dateCutoff != nil && len ( where ) != 0 {
sb . WriteString ( " AND" )
}
if len ( where ) != 0 {
wh := processWhere ( where )
sb . Grow ( ( len ( wh ) * 8 ) - 5 )
for i , loc := range wh {
if i != 0 {
sb . WriteString ( " AND " )
}
for _ , token := range loc . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
sb . WriteString ( " " )
sb . WriteString ( token . Contents )
case TokenColumn :
sb . WriteString ( " `" )
sb . WriteString ( token . Contents )
sb . WriteString ( "`" )
case TokenString :
sb . WriteString ( " '" )
sb . WriteString ( token . Contents )
sb . WriteString ( "'" )
default :
return errors . New ( "This token doesn't exist o_o" )
}
}
}
}
return nil
2020-04-20 23:39:35 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildOrderby ( orderby string ) ( q string ) {
2022-02-21 03:32:53 +00:00
if len ( orderby ) != 0 {
var sb strings . Builder
ord := processOrderby ( orderby )
sb . Grow ( 10 + ( len ( ord ) * 8 ) - 1 )
sb . WriteString ( " ORDER BY " )
for i , col := range ord {
// TODO: We might want to escape this column
if i != 0 {
sb . WriteString ( ",`" )
} else {
sb . WriteString ( "`" )
}
sb . WriteString ( strings . Replace ( col . Column , "." , "`.`" , - 1 ) )
sb . WriteString ( "` " )
sb . WriteString ( strings . ToUpper ( col . Order ) )
}
q = sb . String ( )
}
return q
2017-11-05 01:04:57 +00:00
}
2017-09-03 04:50:31 +00:00
2020-07-13 06:53:04 +00:00
func ( a * MysqlAdapter ) buildOrderbySb ( sb * strings . Builder , orderby string ) {
2022-02-21 03:32:53 +00:00
if len ( orderby ) != 0 {
ord := processOrderby ( orderby )
sb . Grow ( 10 + ( len ( ord ) * 8 ) - 1 )
sb . WriteString ( " ORDER BY " )
for i , col := range ord {
// TODO: We might want to escape this column
if i != 0 {
sb . WriteString ( ",`" )
} else {
sb . WriteString ( "`" )
}
sb . WriteString ( strings . Replace ( col . Column , "." , "`.`" , - 1 ) )
sb . WriteString ( "` " )
sb . WriteString ( strings . ToUpper ( col . Order ) )
}
}
2020-07-13 06:53:04 +00:00
}
2020-04-20 23:39:35 +00:00
func ( a * MysqlAdapter ) SimpleSelect ( name , table , cols , where , orderby , limit string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if len ( cols ) == 0 {
return "" , errors . New ( "No columns found for SimpleSelect" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . WriteString ( "SELECT " )
// Slice up the user friendly strings into something easier to process
for i , col := range strings . Split ( strings . TrimSpace ( cols ) , "," ) {
if i != 0 {
sb . WriteString ( "`,`" )
} else {
sb . WriteRune ( '`' )
}
sb . WriteString ( strings . TrimSpace ( col ) )
}
sb . WriteString ( "`FROM`" )
sb . WriteString ( table )
sb . WriteRune ( '`' )
err := a . buildWhere ( where , sb )
if err != nil {
return "" , err
}
a . buildOrderbySb ( sb , orderby )
a . buildLimitSb ( sb , limit )
q := strings . TrimSpace ( sb . String ( ) )
queryStrPool . Put ( sb )
a . pushStatement ( name , "select" , q )
return q , nil
2017-06-05 11:57:27 +00:00
}
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) ComplexSelect ( preBuilder * selectPrebuilder ) ( out string , e error ) {
2022-02-21 03:32:53 +00:00
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
e = a . complexSelect ( preBuilder , sb )
out = sb . String ( )
queryStrPool . Put ( sb )
a . pushStatement ( preBuilder . name , "select" , out )
return out , e
2019-06-11 05:23:25 +00:00
}
2020-04-20 23:39:35 +00:00
const cslen1 = len ( "SELECT FROM ``" )
2021-04-29 22:33:02 +00:00
const cslen2 = len ( "WHERE``IN(" )
2019-12-31 21:57:54 +00:00
2019-06-11 05:23:25 +00:00
func ( a * MysqlAdapter ) complexSelect ( preBuilder * selectPrebuilder , sb * strings . Builder ) error {
2022-02-21 03:32:53 +00:00
if preBuilder . table == "" {
return errors . New ( "You need a name for this table" )
}
if len ( preBuilder . columns ) == 0 {
return errors . New ( "No columns found for ComplexSelect" )
}
cols := a . buildJoinColumns ( preBuilder . columns )
sb . Grow ( cslen1 + len ( cols ) + len ( preBuilder . table ) )
sb . WriteString ( "SELECT " )
sb . WriteString ( cols )
sb . WriteString ( " FROM `" )
sb . WriteString ( preBuilder . table )
sb . WriteRune ( '`' )
// TODO: Let callers have a Where() and a InQ()
if preBuilder . inChain != nil {
sb . Grow ( cslen2 + len ( preBuilder . inColumn ) )
sb . WriteString ( "WHERE`" )
sb . WriteString ( preBuilder . inColumn )
sb . WriteString ( "`IN(" )
e := a . complexSelect ( preBuilder . inChain , sb )
if e != nil {
return e
}
sb . WriteRune ( ')' )
} else {
e := a . buildFlexiWhereSb ( sb , preBuilder . where , preBuilder . dateCutoff )
if e != nil {
return e
}
}
a . buildOrderbySb ( sb , preBuilder . orderby )
a . buildLimitSb ( sb , preBuilder . limit )
return nil
2018-01-03 07:46:18 +00:00
}
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func ( a * MysqlAdapter ) SimpleLeftJoin ( name , table1 , table2 , columns , joiners , where , orderby , limit string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table1 == "" {
return "" , errors . New ( "You need a name for the left table" )
}
if table2 == "" {
return "" , errors . New ( "You need a name for the right table" )
}
if len ( columns ) == 0 {
return "" , errors . New ( "No columns found for SimpleLeftJoin" )
}
if len ( joiners ) == 0 {
return "" , errors . New ( "No joiners found for SimpleLeftJoin" )
}
whereStr , err := a . buildJoinWhere ( where )
if err != nil {
return "" , err
}
thalf1 := strings . Split ( strings . Replace ( table1 , " as " , " AS " , - 1 ) , " AS " )
var as1 string
if len ( thalf1 ) == 2 {
as1 = " AS `" + thalf1 [ 1 ] + "`"
}
thalf2 := strings . Split ( strings . Replace ( table2 , " as " , " AS " , - 1 ) , " AS " )
var as2 string
if len ( thalf2 ) == 2 {
as2 = " AS `" + thalf2 [ 1 ] + "`"
}
q := "SELECT" + a . buildJoinColumns ( columns ) + " FROM `" + thalf1 [ 0 ] + "`" + as1 + " LEFT JOIN `" + thalf2 [ 0 ] + "`" + as2 + " ON " + a . buildJoiners ( joiners ) + whereStr + a . buildOrderby ( orderby ) + a . buildLimit ( limit )
q = strings . TrimSpace ( q )
a . pushStatement ( name , "select" , q )
return q , nil
2017-06-12 09:03:14 +00:00
}
Cascade delete attachments properly.
Cascade delete replied to topic events for replies properly.
Cascade delete likes on topic posts properly.
Cascade delete replies and their children properly.
Recalculate user stats properly when items are deleted.
Users can now unlike topic opening posts.
Add a recalculator to fix abnormalities across upgrades.
Try fixing a last_ip daily update bug.
Add Existable interface.
Add Delete method to LikeStore.
Add Each, Exists, Create, CountUser, CountMegaUser and CountBigUser methods to ReplyStore.
Add CountUser, CountMegaUser, CountBigUser methods to TopicStore.
Add Each method to UserStore.
Add Add, Delete and DeleteResource methods to SubscriptionStore.
Add Delete, DeleteByParams, DeleteByParamsExtra and AidsByParamsExtra methods to ActivityStream.
Add Exists method to ProfileReplyStore.
Add DropColumn, RenameColumn and ChangeColumn to the database adapters.
Shorten ipaddress column names to ip.
- topics table.
- replies table
- users_replies table.
- polls_votes table.
Add extra column to activity_stream table.
Fix an issue upgrading sites to MariaDB 10.3 from older versions of Gosora. Please report any other issues you find.
You need to run the updater / patcher for this commit.
2020-01-31 07:22:08 +00:00
func ( a * MysqlAdapter ) SimpleInnerJoin ( name , table1 , table2 , columns , joiners , where , orderby , limit string ) ( string , error ) {
2022-02-21 03:32:53 +00:00
if table1 == "" {
return "" , errors . New ( "You need a name for the left table" )
}
if table2 == "" {
return "" , errors . New ( "You need a name for the right table" )
}
if len ( columns ) == 0 {
return "" , errors . New ( "No columns found for SimpleInnerJoin" )
}
if len ( joiners ) == 0 {
return "" , errors . New ( "No joiners found for SimpleInnerJoin" )
}
whereStr , err := a . buildJoinWhere ( where )
if err != nil {
return "" , err
}
thalf1 := strings . Split ( strings . Replace ( table1 , " as " , " AS " , - 1 ) , " AS " )
var as1 string
if len ( thalf1 ) == 2 {
as1 = " AS `" + thalf1 [ 1 ] + "`"
}
thalf2 := strings . Split ( strings . Replace ( table2 , " as " , " AS " , - 1 ) , " AS " )
var as2 string
if len ( thalf2 ) == 2 {
as2 = " AS `" + thalf2 [ 1 ] + "`"
}
q := "SELECT " + a . buildJoinColumns ( columns ) + " FROM `" + thalf1 [ 0 ] + "`" + as1 + " INNER JOIN `" + thalf2 [ 0 ] + "`" + as2 + " ON " + a . buildJoiners ( joiners ) + whereStr + a . buildOrderby ( orderby ) + a . buildLimit ( limit )
q = strings . TrimSpace ( q )
a . pushStatement ( name , "select" , q )
return q , nil
2017-06-14 07:09:44 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) SimpleUpdateSelect ( up * updatePrebuilder ) ( string , error ) {
2022-02-21 03:32:53 +00:00
sel := up . whereSubQuery
sb := & strings . Builder { }
err := a . buildWhere ( sel . where , sb )
if err != nil {
return "" , err
}
var setter string
for _ , item := range processSet ( up . set ) {
setter += "`" + item . Column + "`="
for _ , token := range item . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr :
setter += token . Contents
case TokenColumn :
setter += "`" + token . Contents + "`"
case TokenString :
setter += "'" + token . Contents + "'"
}
}
setter += ","
}
setter = setter [ 0 : len ( setter ) - 1 ]
q := "UPDATE `" + up . table + "` SET " + setter + " WHERE (SELECT" + a . buildJoinColumns ( sel . columns ) + " FROM `" + sel . table + "`" + sb . String ( ) + a . buildOrderby ( sel . orderby ) + a . buildLimit ( sel . limit ) + ")"
q = strings . TrimSpace ( q )
a . pushStatement ( up . name , "update" , q )
return q , nil
2018-12-27 05:42:41 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) SimpleInsertSelect ( name string , ins DBInsert , sel DBSelect ) ( string , error ) {
2022-02-21 03:32:53 +00:00
sb := & strings . Builder { }
e := a . buildWhere ( sel . Where , sb )
if e != nil {
return "" , e
}
q := "INSERT INTO `" + ins . Table + "`(" + a . buildColumns ( ins . Columns ) + ") SELECT" + a . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table + "`" + sb . String ( ) + a . buildOrderby ( sel . Orderby ) + a . buildLimit ( sel . Limit )
q = strings . TrimSpace ( q )
a . pushStatement ( name , "insert" , q )
return q , nil
2017-06-19 08:06:54 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) SimpleInsertLeftJoin ( name string , ins DBInsert , sel DBJoin ) ( string , error ) {
2022-02-21 03:32:53 +00:00
whereStr , e := a . buildJoinWhere ( sel . Where )
if e != nil {
return "" , e
}
q := "INSERT INTO `" + ins . Table + "`(" + a . buildColumns ( ins . Columns ) + ") SELECT" + a . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table1 + "` LEFT JOIN `" + sel . Table2 + "` ON " + a . buildJoiners ( sel . Joiners ) + whereStr + a . buildOrderby ( sel . Orderby ) + a . buildLimit ( sel . Limit )
q = strings . TrimSpace ( q )
a . pushStatement ( name , "insert" , q )
return q , nil
2017-11-05 01:04:57 +00:00
}
// TODO: Make this more consistent with the other build* methods?
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildJoiners ( joiners string ) ( q string ) {
2022-02-21 03:32:53 +00:00
var qb strings . Builder
for i , j := range processJoiner ( joiners ) {
//q += "`" + j.LeftTable + "`.`" + j.LeftColumn + "` " + j.Operator + " `" + j.RightTable + "`.`" + j.RightColumn + "` AND "
if i != 0 {
qb . WriteString ( "AND`" )
} else {
qb . WriteString ( "`" )
}
qb . WriteString ( j . LeftTable )
qb . WriteString ( "`.`" )
qb . WriteString ( j . LeftColumn )
qb . WriteString ( "` " )
qb . WriteString ( j . Operator )
qb . WriteString ( " `" )
qb . WriteString ( j . RightTable )
qb . WriteString ( "`.`" )
qb . WriteString ( j . RightColumn )
qb . WriteString ( "`" )
}
return qb . String ( )
2017-11-05 01:04:57 +00:00
}
2017-09-03 04:50:31 +00:00
2017-11-05 01:04:57 +00:00
// Add support for BETWEEN x.x
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) buildJoinWhere ( where string ) ( q string , e error ) {
2022-02-21 03:32:53 +00:00
if len ( where ) != 0 {
var qsb strings . Builder
ws := processWhere ( where )
qsb . Grow ( 6 + ( len ( ws ) * 5 ) )
qsb . WriteString ( " WHERE" )
for i , loc := range ws {
if i != 0 {
qsb . WriteString ( " AND" )
}
for _ , token := range loc . Expr {
switch token . Type {
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
qsb . WriteRune ( ' ' )
qsb . WriteString ( token . Contents )
case TokenColumn :
qsb . WriteString ( " `" )
halves := strings . Split ( token . Contents , "." )
if len ( halves ) == 2 {
qsb . WriteString ( halves [ 0 ] )
qsb . WriteString ( "`.`" )
qsb . WriteString ( halves [ 1 ] )
} else {
qsb . WriteString ( token . Contents )
}
qsb . WriteRune ( '`' )
case TokenString :
qsb . WriteString ( " '" )
qsb . WriteString ( token . Contents )
qsb . WriteRune ( '\'' )
default :
return qsb . String ( ) , errors . New ( "This token doesn't exist o_o" )
}
}
}
return qsb . String ( ) , nil
}
return q , nil
2017-11-05 01:04:57 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildLimit ( limit string ) ( q string ) {
2022-02-21 03:32:53 +00:00
if limit != "" {
q = " LIMIT " + limit
}
return q
2017-06-25 09:56:39 +00:00
}
2020-07-13 06:53:04 +00:00
func ( a * MysqlAdapter ) buildLimitSb ( sb * strings . Builder , limit string ) {
2022-02-21 03:32:53 +00:00
if limit != "" {
sb . WriteString ( " LIMIT " )
sb . WriteString ( limit )
}
2020-07-13 06:53:04 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildJoinColumns ( cols string ) ( q string ) {
2022-02-21 03:32:53 +00:00
for _ , col := range processColumns ( cols ) {
// TODO: Move the stirng and number logic to processColumns?
// TODO: Error if [0] doesn't exist
firstChar := col . Left [ 0 ]
if firstChar == '\'' {
col . Type = TokenString
} else {
_ , e := strconv . Atoi ( string ( firstChar ) )
if e == nil {
col . Type = TokenNumber
}
}
// Escape the column names, just in case we've used a reserved keyword
source := col . Left
if col . Table != "" {
source = "`" + col . Table + "`.`" + source + "`"
} else if col . Type != TokenScope && col . Type != TokenFunc && col . Type != TokenNumber && col . Type != TokenSub && col . Type != TokenString {
source = "`" + source + "`"
}
var alias string
if col . Alias != "" {
alias = " AS `" + col . Alias + "`"
}
q += " " + source + alias + ","
}
return q [ 0 : len ( q ) - 1 ]
2017-11-05 03:58:19 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) SimpleInsertInnerJoin ( name string , ins DBInsert , sel DBJoin ) ( string , error ) {
2022-02-21 03:32:53 +00:00
whereStr , err := a . buildJoinWhere ( sel . Where )
if err != nil {
return "" , err
}
q := "INSERT INTO `" + ins . Table + "`(" + a . buildColumns ( ins . Columns ) + ") SELECT" + a . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table1 + "` INNER JOIN `" + sel . Table2 + "` ON " + a . buildJoiners ( sel . Joiners ) + whereStr + a . buildOrderby ( sel . Orderby ) + a . buildLimit ( sel . Limit )
q = strings . TrimSpace ( q )
a . pushStatement ( name , "insert" , q )
return q , nil
2017-06-19 08:06:54 +00:00
}
2021-04-29 22:33:02 +00:00
const sclen1 = len ( "SELECT COUNT(*) FROM``" )
2020-04-20 23:39:35 +00:00
2021-04-29 22:33:02 +00:00
func ( a * MysqlAdapter ) SimpleCount ( name , table , where , limit string ) ( q string , e error ) {
2022-02-21 03:32:53 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
var sb * strings . Builder
ii := queryStrPool . Get ( )
if ii == nil {
sb = & strings . Builder { }
} else {
sb = ii . ( * strings . Builder )
sb . Reset ( )
}
sb . Grow ( sclen1 + len ( table ) )
sb . WriteString ( "SELECT COUNT(*) FROM`" )
sb . WriteString ( table )
sb . WriteRune ( '`' )
if e = a . buildWhere ( where , sb ) ; e != nil {
return "" , e
}
a . buildLimitSb ( sb , limit )
q = strings . TrimSpace ( sb . String ( ) )
queryStrPool . Put ( sb )
a . pushStatement ( name , "select" , q )
return q , nil
2017-06-05 11:57:27 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) Builder ( ) * prebuilder {
2022-02-21 03:32:53 +00:00
return & prebuilder { a }
2017-11-12 11:29:23 +00:00
}
2019-08-14 10:39:04 +00:00
func ( a * MysqlAdapter ) Write ( ) error {
2022-02-21 03:32:53 +00:00
var stmts , body string
for _ , name := range a . BufferOrder {
if name [ 0 ] == '_' {
continue
}
stmt := a . Buffer [ name ]
// ? - Table creation might be a little complex for Go to do outside a SQL file :(
if stmt . Type == "upsert" {
stmts += "\t" + name + " *qgen.MySQLUpsertCallback\n"
body += `
dl ( "Preparing ` + name + ` statement." )
stmts . ` + name + ` , e = qgen . PrepareMySQLUpsertCallback ( db , "` + stmt.Contents + `" )
if e != nil {
l ( "Error in ` + name + ` statement." )
return e
}
`
} else if stmt . Type != "create-table" {
stmts += "\t" + name + " *sql.Stmt\n"
body += `
dl ( "Preparing ` + name + ` statement." )
stmts . ` + name + ` , e = db . Prepare ( "` + stmt.Contents + `" )
if e != nil {
l ( "Error in ` + name + ` statement." )
return e
}
`
}
}
// TODO: Move these custom queries out of this file
out := ` // +build !pgsql,!mssql
2017-07-12 11:05:18 +00:00
2017-06-14 09:55:47 +00:00
/* This file was generated by Gosora's Query Generator. Please try to avoid modifying this file, as it might change at any time. */
2017-07-12 11:05:18 +00:00
2017-06-05 11:57:27 +00:00
package main
2021-04-29 22:33:02 +00:00
import (
2022-02-21 03:32:53 +00:00
"log"
"database/sql"
c "github.com/Azareal/Gosora/common"
//"github.com/Azareal/Gosora/query_gen"
2021-04-29 22:33:02 +00:00
)
2017-06-05 11:57:27 +00:00
2017-09-03 04:50:31 +00:00
// nolint
2017-11-05 09:55:34 +00:00
type Stmts struct {
2017-06-13 07:12:58 +00:00
` + stmts + `
2022-02-21 03:32:53 +00:00
getActivityFeedByWatcher * sql . Stmt
//getActivityFeedByWatcherAfter *sql.Stmt
getActivityCountByWatcher * sql . Stmt
2017-11-05 09:55:34 +00:00
2022-02-21 03:32:53 +00:00
Mocks bool
2017-11-05 09:55:34 +00:00
}
2017-09-03 04:50:31 +00:00
// nolint
2021-04-29 22:33:02 +00:00
func _gen_mysql ( ) ( e error ) {
2022-02-21 03:32:53 +00:00
dl := c . DebugLog
dl ( "Building the generated statements" )
l := log . Print
_ = l
2017-06-13 07:12:58 +00:00
` + body + `
2022-02-21 03:32:53 +00:00
return nil
2017-06-05 11:57:27 +00:00
}
`
2022-02-21 03:32:53 +00:00
return writeFile ( "./gen_mysql.go" , out )
2017-06-05 11:57:27 +00:00
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
// Internal methods, not exposed in the interface
2020-01-02 05:28:36 +00:00
func ( a * MysqlAdapter ) pushStatement ( name , stype , q string ) {
2022-02-21 03:32:53 +00:00
if name == "" {
return
}
a . Buffer [ name ] = DBStmt { q , stype }
a . BufferOrder = append ( a . BufferOrder , name )
2017-06-05 11:57:27 +00:00
}
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
2020-01-02 05:28:36 +00:00
func ( a * MysqlAdapter ) stringyType ( ct string ) bool {
2022-02-21 03:32:53 +00:00
ct = strings . ToLower ( ct )
return ct == "varchar" || ct == "tinytext" || ct == "text" || ct == "mediumtext" || ct == "longtext" || ct == "char" || ct == "datetime" || ct == "timestamp" || ct == "time" || ct == "date"
Added the Social Groups plugin. This is still under construction.
Made a few improvements to the ForumStore, including bringing it's API closer in line with the other datastores, adding stubs for future subforum functionality, and improving efficiency in a few places.
The auth interface now handles all the authentication stuff.
Renamed the debug config variable to debug_mode.
Added the PluginPerms API.
Internal Errors will now dump the stack trace in the console.
Added support for installable plugins.
Refactored the routing logic so that the router now handles the common PreRoute logic(exc. /static/)
Added the CreateTable method to the query generator. It might need some tweaking to better support other database systems.
Added the same CreateTable method to the query builder.
Began work on PostgreSQL support.
Added the string-string hook type
Added the pre_render hook type.
Added the ParentID and ParentType fields to forums.
Added the get_forum_url_prefix function.
Added a more generic build_slug function.
Added the get_topic_url_prefix function.
Added the override_perms and override_forum_perms functions for bulk setting and unsetting permissions.
Added more ExtData fields in a few structs and removed them on the Perms struct as the PluginPerms API supersedes them there.
Plugins can now see the router instance.
The plugin initialisation handlers can now throw errors.
Plugins are now initialised after all the forum's subsystems are.
Refactored the unit test logic. For instance, we now use the proper .Log method rather than fmt.Println in many cases.
Sorry, we'll have to break Github's generated file detection, as the build instructions aren't working, unless I put them at the top, and they're far, far more important than getting Github to recognise the generated code as generated code.
Fixed an issue with mysql.go's _init_database() overwriting the dbpassword variable. Not a huge issue, but it is a "gotcha" for those not expecting a ':' at the start.
Fixed an issue with forum creation where the forum permissions didn't get cached.
Fixed a bug in plugin_bbcode where negative numbers in rand would crash Gosora.
Made the outputs of plugin_markdown and plugin_bbcode more compliant with the tests.
Revamped the phrase system to make it easier for us to add language pack related features in the future.
Added the WidgetMenu widget type.
Revamped the theme again. I'm experimenting to see which approach I like most.
- Excuse the little W3C rage. Some things about CSS drive me crazy :p
Tests:
Added 22 bbcode_full_parse tests.
Added 19 bbcode_regex_parse tests.
Added 27 markdown_parse tests.
Added four UserStore tests. More to come when the test database functionality is added.
Added 18 name_to_slug tests.
Hooks:
Added the pre_render hook.
Added the pre_render_forum_list hook.
Added the pre_render_view_forum hook.
Added the pre_render_topic_list hook.
Added the pre_render_view_topic hook.
Added the pre_render_profile hook.
Added the pre_render_custom_page hook.
Added the pre_render_overview hook.
Added the pre_render_create_topic hook.
Added the pre_render_account_own_edit_critical hook.
Added the pre_render_account_own_edit_avatar hook.
Added the pre_render_account_own_edit_username hook.
Added the pre_render_account_own_edit_email hook.
Added the pre_render_login hook.
Added the pre_render_register hook.
Added the pre_render_ban hook.
Added the pre_render_panel_dashboard hook.
Added the pre_render_panel_forums hook.
Added the pre_render_panel_delete_forum hook.
Added the pre_render_panel_edit_forum hook.
Added the pre_render_panel_settings hook.
Added the pre_render_panel_setting hook.
Added the pre_render_panel_plugins hook.
Added the pre_render_panel_users hook.
Added the pre_render_panel_edit_user hook.
Added the pre_render_panel_groups hook.
Added the pre_render_panel_edit_group hook.
Added the pre_render_panel_edit_group_perms hook.
Added the pre_render_panel_themes hook.
Added the pre_render_panel_mod_log hook.
Added the pre_render_error hook.
Added the pre_render_security_error hook.
Added the create_group_preappend hook.
Added the intercept_build_widgets hook.
Added the simple_forum_check_pre_perms hook.
Added the forum_check_pre_perms hook.
2017-07-09 12:06:04 +00:00
}