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 (
2018-03-31 05:25:27 +00:00
"database/sql"
2018-01-21 11:17:43 +00:00
"errors"
2018-08-29 03:46:27 +00:00
"os"
2018-08-29 01:37:57 +00:00
"runtime"
2018-01-21 11:17:43 +00:00
"strconv"
"strings"
2018-03-31 05:25:27 +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 ( ) {
2017-11-12 05:25:04 +00:00
Registry = append ( Registry ,
& MysqlAdapter { Name : "mysql" , Buffer : make ( map [ string ] DBStmt ) } ,
2017-06-13 07:12:58 +00:00
)
2017-06-05 11:57:27 +00:00
}
2017-10-30 09:57:08 +00:00
type MysqlAdapter struct {
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
Name string // ? - Do we really need this? Can't we hard-code this?
2017-11-12 05:25:04 +00:00
Buffer map [ string ] DBStmt
2017-06-13 07:12:58 +00:00
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 {
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 {
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 {
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 ) {
2018-03-31 05:25:27 +00:00
dbCollation , ok := config [ "collation" ]
if ! ok {
return nil , ErrNoCollation
}
var dbpassword string
if config [ "password" ] != "" {
dbpassword = ":" + config [ "password" ]
}
2018-08-29 01:37:57 +00:00
// First try opening a pipe as those are faster
if runtime . GOOS == "linux" {
var dbsocket = "/tmp/mysql.sock"
if config [ "socket" ] != "" {
dbsocket = config [ "socket" ]
}
2018-08-29 03:46:27 +00:00
// 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 )
2018-08-29 01:59:43 +00:00
if err == nil {
2018-08-29 03:46:27 +00:00
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 ( )
}
2018-08-29 01:37:57 +00:00
}
}
2018-03-31 05:25:27 +00:00
// 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 ( )
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) DbVersion ( ) string {
2018-03-31 05:25:27 +00:00
return "SELECT VERSION()"
}
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) DropTable ( name , table string ) ( string , error ) {
2018-05-11 05:41:51 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
2019-12-31 21:57:54 +00:00
q := "DROP TABLE IF EXISTS `" + table + "`;"
2018-12-27 05:42:41 +00:00
// 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
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "drop-table" , q )
return q , nil
2018-05-11 05:41:51 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) CreateTable ( name string , table string , charset string , collation string , columns [ ] DBTableColumn , keys [ ] DBTableKey ) ( string , error ) {
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
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if len ( columns ) == 0 {
return "" , errors . New ( "You can't have a table with no columns" )
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
q := "CREATE TABLE `" + table + "` ("
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
for _ , column := range columns {
2019-12-31 21:57:54 +00:00
column , size , end := a . parseColumn ( column )
q += "\n\t`" + column . Name + "` " + column . Type + size + end + ","
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
}
2017-09-03 04:50:31 +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
if len ( keys ) > 0 {
for _ , key := range keys {
2019-12-31 21:57:54 +00:00
q += "\n\t" + key . Type
2017-07-12 11:05:18 +00:00
if key . Type != "unique" {
2019-12-31 21:57:54 +00:00
q += " key"
2017-07-12 11:05:18 +00:00
}
2019-05-06 04:04:00 +00:00
if key . Type == "foreign" {
cols := strings . Split ( key . Columns , "," )
2019-12-31 21:57:54 +00:00
q += "(`" + cols [ 0 ] + "`) REFERENCES `" + key . FTable + "`(`" + cols [ 1 ] + "`)"
2019-05-06 04:04:00 +00:00
if key . Cascade {
2019-12-31 21:57:54 +00:00
q += " ON DELETE CASCADE"
2019-05-06 04:04:00 +00:00
}
2019-12-31 21:57:54 +00:00
q += ","
2019-05-06 04:04:00 +00:00
} else {
2019-12-31 21:57:54 +00:00
q += "("
2019-05-06 04:04:00 +00:00
for _ , column := range strings . Split ( key . Columns , "," ) {
2019-12-31 21:57:54 +00:00
q += "`" + column + "`,"
2019-05-06 04:04:00 +00:00
}
2019-12-31 21:57:54 +00:00
q = q [ 0 : len ( q ) - 1 ] + "),"
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
}
}
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
q = q [ 0 : len ( q ) - 1 ] + "\n)"
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
if charset != "" {
2019-12-31 21:57:54 +00:00
q += " CHARSET=" + charset
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
}
if collation != "" {
2019-12-31 21:57:54 +00:00
q += " COLLATE " + collation
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
}
2017-09-03 04:50:31 +00:00
2018-12-27 05:42:41 +00:00
// 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
2019-12-31 21:57:54 +00:00
q += ";"
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
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) parseColumn ( column DBTableColumn ) ( col DBTableColumn , size string , end string ) {
2018-05-27 09:36:35 +00:00
// Make it easier to support Cassandra in the future
if column . Type == "createdAt" {
column . Type = "datetime"
2018-10-07 01:33:03 +00:00
// MySQL doesn't support this x.x
/ * if column . Default == "" {
2018-10-06 13:14:11 +00:00
column . Default = "UTC_TIMESTAMP()"
2018-10-07 01:33:03 +00:00
} * /
2018-05-27 09:36:35 +00:00
} else if column . Type == "json" {
column . Type = "text"
}
if column . Size > 0 {
size = "(" + strconv . Itoa ( column . Size ) + ")"
}
// TODO: Exclude the other variants of text like mediumtext and longtext too
if column . Default != "" && column . Type != "text" {
end = " DEFAULT "
2018-10-07 01:33:03 +00:00
/ * if column . Type == "datetime" && column . Default [ len ( column . Default ) - 1 ] == ')' {
2018-10-06 13:14:11 +00:00
end += column . Default
2019-12-31 21:57:54 +00:00
} else * / if a . stringyType ( column . Type ) && column . Default != "''" {
2018-05-27 09:36:35 +00:00
end += "'" + column . Default + "'"
} else {
end += column . Default
}
}
if column . Null {
end += " null"
} else {
end += " not null"
}
if column . AutoIncrement {
end += " AUTO_INCREMENT"
}
return column , size , end
}
// TODO: Support AFTER column
// TODO: Test to make sure everything works here
2019-05-06 04:04:00 +00:00
func ( a * MysqlAdapter ) AddColumn ( name string , table string , column DBTableColumn , key * DBTableKey ) ( string , error ) {
2018-05-27 09:36:35 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
2019-05-06 04:04:00 +00:00
column , size , end := a . parseColumn ( column )
2019-12-31 21:57:54 +00:00
q := "ALTER TABLE `" + table + "` ADD COLUMN " + "`" + column . Name + "` " + column . Type + size + end
2019-01-21 12:27:59 +00:00
if key != nil {
2019-12-31 21:57:54 +00:00
q += " " + key . Type
2019-01-21 12:27:59 +00:00
if key . Type != "unique" {
2019-12-31 21:57:54 +00:00
q += " key"
2019-01-21 12:27:59 +00:00
} else if key . Type == "primary" {
2019-12-31 21:57:54 +00:00
q += " first"
2019-01-21 12:27:59 +00:00
}
}
2018-12-27 05:42:41 +00:00
// 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
2019-12-31 21:57:54 +00:00
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 ) {
2018-12-31 09:03:49 +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" )
}
2019-12-31 21:57:54 +00:00
q := "ALTER TABLE `" + table + "` ADD INDEX " + "`i_" + iname + "` (`" + colname + "`);"
2018-12-31 09:03:49 +00:00
// 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
2019-12-31 21:57:54 +00:00
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
2019-05-06 04:04:00 +00:00
func ( a * MysqlAdapter ) AddKey ( name string , table string , column string , key DBTableKey ) ( string , error ) {
2019-02-23 06:29:19 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
2019-12-31 21:57:54 +00:00
var q string
2019-05-06 04:04:00 +00:00
if key . Type == "fulltext" {
2019-12-31 21:57:54 +00:00
q = "ALTER TABLE `" + table + "` ADD FULLTEXT(`" + column + "`)"
2019-05-06 04:04:00 +00:00
} else {
2019-02-23 06:29:19 +00:00
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
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "add-key" , q )
return q , nil
2019-05-06 04:04:00 +00:00
}
func ( a * MysqlAdapter ) AddForeignKey ( name string , table string , column string , ftable string , fcolumn string , cascade bool ) ( out string , e error ) {
2019-12-31 21:57:54 +00:00
c := func ( str string , val bool ) {
2019-05-06 04:04:00 +00:00
if e != nil || ! val {
return
}
2019-12-31 21:57:54 +00:00
e = errors . New ( "You need a " + str + " for this table" )
2019-05-06 04:04:00 +00:00
}
2019-12-31 21:57:54 +00:00
c ( "name" , table == "" )
c ( "column" , column == "" )
c ( "ftable" , ftable == "" )
c ( "fcolumn" , fcolumn == "" )
2019-05-06 04:04:00 +00:00
if e != nil {
return "" , e
}
2019-12-31 21:57:54 +00:00
q := "ALTER TABLE `" + table + "` ADD CONSTRAINT `fk_" + column + "` FOREIGN KEY(`" + column + "`) REFERENCES `" + ftable + "`(`" + fcolumn + "`)"
2019-05-06 04:04:00 +00:00
if cascade {
2019-12-31 21:57:54 +00:00
q += " ON DELETE CASCADE"
2019-05-06 04:04:00 +00:00
}
// 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
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "add-foreign-key" , q )
return q , nil
2019-02-23 06:29:19 +00:00
}
2019-06-11 12:43:33 +00:00
var silen1 = len ( "INSERT INTO ``() VALUES () " )
2019-12-31 21:57:54 +00:00
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleInsert ( name , table , columns , fields string ) ( string , error ) {
2017-06-05 11:57:27 +00:00
if table == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this table" )
2017-06-05 11:57:27 +00:00
}
2017-09-03 04:50:31 +00:00
2019-06-11 12:43:33 +00:00
var sb strings . Builder
sb . Grow ( silen1 + len ( table ) )
sb . WriteString ( "INSERT INTO `" )
sb . WriteString ( table )
sb . WriteString ( "`(" )
2018-04-22 12:33:56 +00:00
if columns != "" {
2019-12-31 21:57:54 +00:00
sb . WriteString ( a . buildColumns ( columns ) )
2019-06-11 12:43:33 +00:00
sb . WriteString ( ") VALUES (" )
fs := processFields ( fields )
sb . Grow ( len ( fs ) * 3 )
for i , field := range fs {
if i != 0 {
sb . WriteString ( "," )
}
2018-04-22 12:33:56 +00:00
nameLen := len ( field . Name )
if field . Name [ 0 ] == '"' && field . Name [ nameLen - 1 ] == '"' && nameLen >= 3 {
field . Name = "'" + field . Name [ 1 : nameLen - 1 ] + "'"
}
if field . Name [ 0 ] == '\'' && field . Name [ nameLen - 1 ] == '\'' && nameLen >= 3 {
field . Name = "'" + strings . Replace ( field . Name [ 1 : nameLen - 1 ] , "'" , "''" , - 1 ) + "'"
}
2019-06-11 12:43:33 +00:00
sb . WriteString ( field . Name )
2017-10-14 07:39:22 +00:00
}
2019-06-11 12:43:33 +00:00
sb . WriteString ( ")" )
2018-04-23 21:08:31 +00:00
} else {
2019-06-11 12:43:33 +00:00
sb . WriteString ( ") VALUES ()" )
2017-06-05 11:57:27 +00:00
}
2017-09-03 04:50:31 +00:00
2018-12-27 05:42:41 +00:00
// 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
2019-06-11 12:43:33 +00:00
q := sb . String ( )
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "insert" , q )
2019-06-11 12:43:33 +00:00
return q , nil
2017-06-05 11:57:27 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildColumns ( columns string ) ( q string ) {
2018-04-22 12:33:56 +00:00
if columns == "" {
return ""
}
2017-11-05 01:04:57 +00:00
// Escape the column names, just in case we've used a reserved keyword
2019-12-31 21:57:54 +00:00
for _ , col := range processColumns ( columns ) {
if col . Type == TokenFunc {
q += col . Left + ","
2017-11-05 01:04:57 +00:00
} else {
2019-12-31 21:57:54 +00:00
q += "`" + col . Left + "`,"
2017-11-05 01:04:57 +00:00
}
}
2019-12-31 21:57:54 +00:00
return q [ 0 : len ( q ) - 1 ]
2017-11-05 01:04:57 +00:00
}
2017-10-16 07:32:58 +00:00
// ! DEPRECATED
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleReplace ( name , table , columns , fields string ) ( string , error ) {
2017-06-10 07:58:15 +00:00
if table == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this table" )
2017-06-10 07:58:15 +00:00
}
if len ( columns ) == 0 {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "No columns found for SimpleInsert" )
2017-06-10 07:58:15 +00:00
}
if len ( fields ) == 0 {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "No input data found for SimpleInsert" )
2017-06-10 07:58:15 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
q := "REPLACE INTO `" + table + "`(" + a . buildColumns ( columns ) + ") VALUES ("
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
for _ , field := range processFields ( fields ) {
2019-12-31 21:57:54 +00:00
q += field . Name + ","
2017-06-10 07:58:15 +00:00
}
2019-12-31 21:57:54 +00:00
q = q [ 0 : len ( q ) - 1 ]
2017-09-03 04:50:31 +00:00
2018-12-27 05:42:41 +00:00
// 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
2019-12-31 21:57:54 +00:00
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 ) {
2017-10-16 07:32:58 +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" )
}
2019-12-31 21:57:54 +00:00
q := "INSERT INTO `" + table + "`("
parsedFields := processFields ( fields )
2017-10-16 07:32:58 +00:00
var insertColumns string
var insertValues string
2019-12-31 21:57:54 +00:00
setBit := ") ON DUPLICATE KEY UPDATE "
2017-10-16 07:32:58 +00:00
2019-12-31 21:57:54 +00:00
for columnID , col := range processColumns ( columns ) {
2017-10-16 07:32:58 +00:00
field := parsedFields [ columnID ]
2019-12-31 21:57:54 +00:00
if col . Type == TokenFunc {
insertColumns += col . Left + ","
2017-10-16 07:32:58 +00:00
insertValues += field . Name + ","
2019-12-31 21:57:54 +00:00
setBit += col . Left + " = " + field . Name + " AND "
2017-10-16 07:32:58 +00:00
} else {
2019-12-31 21:57:54 +00:00
insertColumns += "`" + col . Left + "`,"
2017-10-16 07:32:58 +00:00
insertValues += field . Name + ","
2019-12-31 21:57:54 +00:00
setBit += "`" + col . Left + "` = " + field . Name + " AND "
2017-10-16 07:32:58 +00:00
}
}
insertColumns = insertColumns [ 0 : len ( insertColumns ) - 1 ]
insertValues = insertValues [ 0 : len ( insertValues ) - 1 ]
insertColumns += ") VALUES (" + insertValues
setBit = setBit [ 0 : len ( setBit ) - 5 ]
2019-12-31 21:57:54 +00:00
q += insertColumns + setBit
2017-10-16 07:32:58 +00:00
2018-12-27 05:42:41 +00:00
// 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
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "upsert" , q )
return q , nil
2017-10-16 07:32:58 +00:00
}
2019-06-11 05:44:31 +00:00
var sulen1 = len ( "UPDATE `` SET " )
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) SimpleUpdate ( up * updatePrebuilder ) ( string , error ) {
2018-12-27 05:42:41 +00:00
if up . table == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this table" )
2017-06-07 10:07:40 +00:00
}
2018-12-27 05:42:41 +00:00
if up . set == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need to set data in this update statement" )
2017-06-07 10:07:40 +00:00
}
2019-06-11 05:44:31 +00:00
var sb strings . Builder
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 )
2019-12-31 21:57:54 +00:00
sb . WriteString ( "`=" )
2017-06-07 10:07:40 +00:00
for _ , token := range item . Expr {
2017-09-03 04:50:31 +00:00
switch token . Type {
2019-12-31 21:57:54 +00:00
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr :
2019-06-11 05:44:31 +00:00
sb . WriteString ( " " )
sb . WriteString ( token . Contents )
2019-12-31 21:57:54 +00:00
case TokenColumn :
2019-06-11 05:44:31 +00:00
sb . WriteString ( " `" )
sb . WriteString ( token . Contents )
sb . WriteString ( "`" )
2019-12-31 21:57:54 +00:00
case TokenString :
2019-06-11 05:44:31 +00:00
sb . WriteString ( " '" )
sb . WriteString ( token . Contents )
sb . WriteString ( "'" )
2017-06-07 10:07:40 +00:00
}
}
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
whereStr , err := a . buildFlexiWhere ( up . where , up . dateCutoff )
2019-06-11 05:44:31 +00:00
sb . WriteString ( whereStr )
2017-11-05 01:04:57 +00:00
if err != nil {
2019-06-11 05:44:31 +00:00
return sb . String ( ) , err
2017-06-07 10:07:40 +00:00
}
2017-09-03 04:50:31 +00:00
2018-12-27 05:42:41 +00:00
// 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
2019-06-11 05:44:31 +00:00
q := sb . String ( )
2019-12-31 21:57:54 +00:00
a . pushStatement ( up . name , "update" , q )
2019-06-05 04:57:10 +00:00
return q , nil
2017-06-05 11:57:27 +00:00
}
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleDelete ( name , table , where string ) ( string , error ) {
2017-06-12 09:03:14 +00:00
if table == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this table" )
2017-06-12 09:03:14 +00:00
}
if where == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need to specify what data you want to delete" )
2017-06-12 09:03:14 +00:00
}
2019-12-31 21:57:54 +00:00
q := "DELETE FROM `" + table + "` WHERE"
2017-09-03 04:50:31 +00:00
2017-06-19 08:06:54 +00:00
// Add support for BETWEEN x.x
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
for _ , loc := range processWhere ( where ) {
2017-06-19 08:06:54 +00:00
for _ , token := range loc . Expr {
2017-09-03 04:50:31 +00:00
switch token . Type {
2019-12-31 21:57:54 +00:00
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot :
2019-06-05 04:57:10 +00:00
q += " " + token . Contents
2019-12-31 21:57:54 +00:00
case TokenColumn :
2019-06-05 04:57:10 +00:00
q += " `" + token . Contents + "`"
2019-12-31 21:57:54 +00:00
case TokenString :
2019-06-05 04:57:10 +00:00
q += " '" + token . Contents + "'"
2017-09-03 04:50:31 +00:00
default :
panic ( "This token doesn't exist o_o" )
2017-06-19 08:06:54 +00:00
}
2017-06-12 09:03:14 +00:00
}
2019-06-05 04:57:10 +00:00
q += " AND"
2017-06-12 09:03:14 +00:00
}
2017-09-03 04:50:31 +00:00
2019-06-05 04:57:10 +00:00
q = strings . TrimSpace ( q [ 0 : len ( q ) - 4 ] )
2018-12-27 05:42:41 +00:00
// 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
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "delete" , q )
2019-06-05 04:57:10 +00:00
return q , nil
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) ComplexDelete ( b * deletePrebuilder ) ( string , error ) {
2019-06-05 04:57:10 +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" )
}
2019-12-31 21:57:54 +00:00
q := "DELETE FROM `" + b . table + "`"
2019-06-05 04:57:10 +00:00
2019-12-31 21:57:54 +00:00
whereStr , err := a . buildFlexiWhere ( b . where , b . dateCutoff )
2019-06-05 04:57:10 +00:00
if err != nil {
return q , err
}
q += whereStr
// 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
2019-12-31 21:57:54 +00:00
a . pushStatement ( b . name , "delete" , q )
2019-06-05 04:57:10 +00:00
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 ) {
2017-06-12 09:03:14 +00:00
if table == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this table" )
2017-06-12 09:03:14 +00:00
}
2019-12-31 21:57:54 +00:00
q := "DELETE FROM `" + table + "`"
a . pushStatement ( name , "purge" , q )
2019-06-05 04:57:10 +00:00
return q , nil
2017-06-12 09:03:14 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildWhere ( where string ) ( q string , err error ) {
2018-01-03 07:46:18 +00:00
if len ( where ) == 0 {
return "" , nil
}
2019-06-05 04:57:10 +00:00
q = " WHERE"
2018-01-03 07:46:18 +00:00
for _ , loc := range processWhere ( where ) {
for _ , token := range loc . Expr {
switch token . Type {
2019-12-31 21:57:54 +00:00
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
2019-06-05 04:57:10 +00:00
q += " " + token . Contents
2019-12-31 21:57:54 +00:00
case TokenColumn :
2019-06-05 04:57:10 +00:00
q += " `" + token . Contents + "`"
2019-12-31 21:57:54 +00:00
case TokenString :
2019-06-05 04:57:10 +00:00
q += " '" + token . Contents + "'"
2018-01-03 07:46:18 +00:00
default :
2019-06-05 04:57:10 +00:00
return q , errors . New ( "This token doesn't exist o_o" )
2018-01-03 07:46:18 +00:00
}
}
2019-06-05 04:57:10 +00:00
q += " AND"
2018-01-03 07:46:18 +00:00
}
2019-06-05 04:57:10 +00:00
return q [ 0 : len ( q ) - 4 ] , nil
2018-01-03 07:46:18 +00:00
}
// The new version of buildWhere() currently only used in ComplexSelect for complex OO builder queries
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildFlexiWhere ( where string , dateCutoff * dateCutoff ) ( q string , err error ) {
2018-01-03 07:46:18 +00:00
if len ( where ) == 0 && dateCutoff == nil {
return "" , nil
}
2019-06-05 04:57:10 +00:00
q = " WHERE"
2018-01-03 07:46:18 +00:00
if dateCutoff != nil {
2019-05-08 09:50:10 +00:00
if dateCutoff . Type == 0 {
2019-06-05 04:57:10 +00:00
q += " " + dateCutoff . Column + " BETWEEN (UTC_TIMESTAMP() - interval " + strconv . Itoa ( dateCutoff . Quantity ) + " " + dateCutoff . Unit + ") AND UTC_TIMESTAMP() AND"
2019-05-08 09:50:10 +00:00
} else {
2019-06-05 04:57:10 +00:00
q += " " + dateCutoff . Column + " < UTC_TIMESTAMP() - interval " + strconv . Itoa ( dateCutoff . Quantity ) + " " + dateCutoff . Unit + " AND"
2019-05-08 09:50:10 +00:00
}
2018-01-03 07:46:18 +00:00
}
2019-06-05 04:57:10 +00:00
2017-06-05 11:57:27 +00:00
if len ( where ) != 0 {
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
for _ , loc := range processWhere ( where ) {
2017-06-19 08:06:54 +00:00
for _ , token := range loc . Expr {
2017-09-03 04:50:31 +00:00
switch token . Type {
2019-12-31 21:57:54 +00:00
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
2019-06-05 04:57:10 +00:00
q += " " + token . Contents
2019-12-31 21:57:54 +00:00
case TokenColumn :
2019-06-05 04:57:10 +00:00
q += " `" + token . Contents + "`"
2019-12-31 21:57:54 +00:00
case TokenString :
2019-06-05 04:57:10 +00:00
q += " '" + token . Contents + "'"
2017-09-03 04:50:31 +00:00
default :
2019-06-05 04:57:10 +00:00
return q , errors . New ( "This token doesn't exist o_o" )
2017-06-19 08:06:54 +00:00
}
2017-06-05 11:57:27 +00:00
}
2019-06-05 04:57:10 +00:00
q += " AND"
2017-06-05 11:57:27 +00:00
}
}
2019-06-05 04:57:10 +00:00
return q [ 0 : len ( q ) - 4 ] , 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 ) buildOrderby ( orderby string ) ( q string ) {
2017-06-05 11:57:27 +00:00
if len ( orderby ) != 0 {
2019-06-05 04:57:10 +00:00
q = " ORDER BY "
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
for _ , column := range processOrderby ( orderby ) {
2017-10-14 07:39:22 +00:00
// TODO: We might want to escape this column
2019-06-05 04:57:10 +00:00
q += "`" + strings . Replace ( column . Column , "." , "`.`" , - 1 ) + "` " + strings . ToUpper ( column . Order ) + ","
2017-06-05 11:57:27 +00:00
}
2019-06-05 04:57:10 +00:00
q = q [ 0 : len ( q ) - 1 ]
2017-06-05 11:57:27 +00:00
}
2019-06-05 04:57:10 +00:00
return q
2017-11-05 01:04:57 +00:00
}
2017-09-03 04:50:31 +00:00
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleSelect ( name , table , columns , where , orderby , limit string ) ( string , error ) {
2017-11-05 01:04:57 +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 SimpleSelect" )
}
2019-12-31 21:57:54 +00:00
q := "SELECT "
2017-11-05 01:04:57 +00:00
// Slice up the user friendly strings into something easier to process
2018-01-03 07:46:18 +00:00
for _ , column := range strings . Split ( strings . TrimSpace ( columns ) , "," ) {
2019-06-05 04:57:10 +00:00
q += "`" + strings . TrimSpace ( column ) + "`,"
2017-11-05 01:04:57 +00:00
}
2019-06-05 04:57:10 +00:00
q = q [ 0 : len ( q ) - 1 ]
2017-11-05 01:04:57 +00:00
2019-12-31 21:57:54 +00:00
whereStr , err := a . buildWhere ( where )
2017-11-05 01:04:57 +00:00
if err != nil {
2019-06-05 04:57:10 +00:00
return q , err
2017-11-05 01:04:57 +00:00
}
2019-12-31 21:57:54 +00:00
q += " FROM `" + table + "`" + whereStr + a . buildOrderby ( orderby ) + a . buildLimit ( limit )
2017-11-05 01:04:57 +00:00
2019-06-05 04:57:10 +00:00
q = strings . TrimSpace ( q )
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "select" , q )
2019-06-05 04:57:10 +00:00
return q , nil
2017-06-05 11:57:27 +00:00
}
2019-06-11 05:23:25 +00:00
func ( a * MysqlAdapter ) ComplexSelect ( preBuilder * selectPrebuilder ) ( out string , err error ) {
sb := & strings . Builder { }
2019-12-31 21:57:54 +00:00
err = a . complexSelect ( preBuilder , sb )
2019-06-11 05:23:25 +00:00
out = sb . String ( )
a . pushStatement ( preBuilder . name , "select" , out )
return out , err
}
var cslen1 = len ( "SELECT FROM ``" )
var 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 {
2018-01-03 07:46:18 +00:00
if preBuilder . table == "" {
2019-06-11 05:23:25 +00:00
return errors . New ( "You need a name for this table" )
2018-01-03 07:46:18 +00:00
}
if len ( preBuilder . columns ) == 0 {
2019-06-11 05:23:25 +00:00
return errors . New ( "No columns found for ComplexSelect" )
2018-01-03 07:46:18 +00:00
}
2019-12-31 21:57:54 +00:00
2019-06-11 05:23:25 +00:00
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 ( '`' )
2018-01-03 07:46:18 +00:00
2018-01-21 11:17:43 +00:00
// TODO: Let callers have a Where() and a InQ()
if preBuilder . inChain != nil {
2019-06-11 05:23:25 +00:00
sb . Grow ( cslen2 + len ( preBuilder . inColumn ) )
sb . WriteString ( " WHERE `" )
sb . WriteString ( preBuilder . inColumn )
sb . WriteString ( "` IN(" )
2019-12-31 21:57:54 +00:00
err := a . complexSelect ( preBuilder . inChain , sb )
2018-01-21 11:17:43 +00:00
if err != nil {
2019-06-11 05:23:25 +00:00
return err
2018-01-21 11:17:43 +00:00
}
2019-06-11 05:23:25 +00:00
sb . WriteRune ( ')' )
2018-01-21 11:17:43 +00:00
} else {
2019-06-11 05:23:25 +00:00
whereStr , err := a . buildFlexiWhere ( preBuilder . where , preBuilder . dateCutoff )
2018-01-21 11:17:43 +00:00
if err != nil {
2019-06-11 05:23:25 +00:00
return err
2018-01-21 11:17:43 +00:00
}
2019-06-11 05:23:25 +00:00
sb . WriteString ( whereStr )
2018-01-03 07:46:18 +00:00
}
2019-06-11 05:23:25 +00:00
orderby := a . buildOrderby ( preBuilder . orderby )
limit := a . buildLimit ( preBuilder . limit )
sb . Grow ( len ( orderby ) + len ( limit ) )
sb . WriteString ( orderby )
sb . WriteString ( limit )
return nil
2018-01-03 07:46:18 +00:00
}
2019-08-14 10:39:04 +00:00
func ( a * MysqlAdapter ) SimpleLeftJoin ( name string , table1 string , table2 string , columns string , joiners string , where string , orderby string , limit string ) ( string , error ) {
2017-06-05 11:57:27 +00:00
if table1 == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for the left table" )
2017-06-05 11:57:27 +00:00
}
if table2 == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for the right table" )
2017-06-05 11:57:27 +00:00
}
if len ( columns ) == 0 {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "No columns found for SimpleLeftJoin" )
2017-06-05 11:57:27 +00:00
}
if len ( joiners ) == 0 {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "No joiners found for SimpleLeftJoin" )
2017-06-05 11:57:27 +00:00
}
2017-09-03 04:50:31 +00:00
2019-08-14 10:39:04 +00:00
whereStr , err := a . buildJoinWhere ( where )
2017-11-05 01:04:57 +00:00
if err != nil {
2017-11-05 03:58:19 +00:00
return "" , err
2017-06-12 09:03:14 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
thalf1 := strings . Split ( strings . Replace ( table1 , " as " , " AS " , - 1 ) , " AS " )
2019-07-29 01:31:19 +00:00
var as1 string
if len ( thalf1 ) == 2 {
2019-12-31 21:57:54 +00:00
as1 = " AS `" + thalf1 [ 1 ] + "`"
2019-07-29 01:31:19 +00:00
}
2019-12-31 21:57:54 +00:00
thalf2 := strings . Split ( strings . Replace ( table2 , " as " , " AS " , - 1 ) , " AS " )
2019-07-29 01:31:19 +00:00
var as2 string
if len ( thalf2 ) == 2 {
2019-12-31 21:57:54 +00:00
as2 = " AS `" + thalf2 [ 1 ] + "`"
2019-07-29 01:31:19 +00:00
}
2019-12-31 21:57:54 +00:00
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 )
2017-09-03 04:50:31 +00:00
2019-08-14 10:39:04 +00:00
q = strings . TrimSpace ( q )
a . pushStatement ( name , "select" , q )
return q , nil
2017-06-12 09:03:14 +00:00
}
2019-08-14 10:39:04 +00:00
func ( a * MysqlAdapter ) SimpleInnerJoin ( name string , table1 string , table2 string , columns string , joiners string , where string , orderby string , limit string ) ( string , error ) {
2017-06-12 09:03:14 +00:00
if table1 == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for the left table" )
2017-06-12 09:03:14 +00:00
}
if table2 == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for the right table" )
2017-06-12 09:03:14 +00:00
}
if len ( columns ) == 0 {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "No columns found for SimpleInnerJoin" )
2017-06-12 09:03:14 +00:00
}
if len ( joiners ) == 0 {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "No joiners found for SimpleInnerJoin" )
2017-06-12 09:03:14 +00:00
}
2017-09-03 04:50:31 +00:00
2019-08-14 10:39:04 +00:00
whereStr , err := a . buildJoinWhere ( where )
2017-11-05 01:04:57 +00:00
if err != nil {
2017-11-05 03:58:19 +00:00
return "" , err
2017-06-05 11:57:27 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
thalf1 := strings . Split ( strings . Replace ( table1 , " as " , " AS " , - 1 ) , " AS " )
2019-08-14 10:39:04 +00:00
var as1 string
if len ( thalf1 ) == 2 {
2019-12-31 21:57:54 +00:00
as1 = " AS `" + thalf1 [ 1 ] + "`"
2019-08-14 10:39:04 +00:00
}
2019-12-31 21:57:54 +00:00
thalf2 := strings . Split ( strings . Replace ( table2 , " as " , " AS " , - 1 ) , " AS " )
2019-08-14 10:39:04 +00:00
var as2 string
if len ( thalf2 ) == 2 {
2019-12-31 21:57:54 +00:00
as2 = " AS `" + thalf2 [ 1 ] + "`"
2019-08-14 10:39:04 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
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 )
2019-08-14 10:39:04 +00:00
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 ) {
2018-12-27 05:42:41 +00:00
sel := up . whereSubQuery
2019-12-31 21:57:54 +00:00
whereStr , err := a . buildWhere ( sel . where )
2018-12-27 05:42:41 +00:00
if err != nil {
return "" , err
}
var setter string
for _ , item := range processSet ( up . set ) {
2019-12-31 21:57:54 +00:00
setter += "`" + item . Column + "`="
2018-12-27 05:42:41 +00:00
for _ , token := range item . Expr {
switch token . Type {
2019-12-31 21:57:54 +00:00
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr :
setter += token . Contents
case TokenColumn :
setter += "`" + token . Contents + "`"
case TokenString :
setter += "'" + token . Contents + "'"
2018-12-27 05:42:41 +00:00
}
}
setter += ","
}
setter = setter [ 0 : len ( setter ) - 1 ]
2019-12-31 21:57:54 +00:00
q := "UPDATE `" + up . table + "` SET " + setter + " WHERE (SELECT" + a . buildJoinColumns ( sel . columns ) + " FROM `" + sel . table + "`" + whereStr + 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 ) {
whereStr , err := a . buildWhere ( sel . Where )
2017-11-05 01:04:57 +00:00
if err != nil {
2017-11-05 03:58:19 +00:00
return "" , err
2017-06-19 08:06:54 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
q := "INSERT INTO `" + ins . Table + "`(" + a . buildColumns ( ins . Columns ) + ") SELECT" + a . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table + "`" + whereStr + a . buildOrderby ( sel . Orderby ) + a . buildLimit ( sel . Limit )
2019-06-05 04:57:10 +00:00
q = strings . TrimSpace ( q )
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "insert" , q )
2019-06-05 04:57:10 +00:00
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 ) {
whereStr , err := a . buildJoinWhere ( sel . Where )
2017-11-05 01:04:57 +00:00
if err != nil {
2017-11-05 03:58:19 +00:00
return "" , err
2017-11-05 01:04:57 +00:00
}
2019-12-31 21:57:54 +00:00
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 )
2019-06-05 04:57:10 +00:00
q = strings . TrimSpace ( q )
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "insert" , q )
2019-06-05 04:57:10 +00:00
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 ) {
for _ , j := range processJoiner ( joiners ) {
q += "`" + j . LeftTable + "`.`" + j . LeftColumn + "` " + j . Operator + " `" + j . RightTable + "`.`" + j . RightColumn + "` AND "
2017-06-25 09:56:39 +00:00
}
2017-11-05 01:04:57 +00:00
// Remove the trailing AND
2019-06-05 04:57:10 +00:00
return q [ 0 : len ( q ) - 4 ]
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
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildJoinWhere ( where string ) ( q string , err error ) {
2017-11-05 01:04:57 +00:00
if len ( where ) != 0 {
2019-06-05 04:57:10 +00:00
q = " WHERE"
2017-11-05 01:04:57 +00:00
for _ , loc := range processWhere ( where ) {
2017-06-25 09:56:39 +00:00
for _ , token := range loc . Expr {
2017-09-03 04:50:31 +00:00
switch token . Type {
2019-12-31 21:57:54 +00:00
case TokenFunc , TokenOp , TokenNumber , TokenSub , TokenOr , TokenNot , TokenLike :
2019-06-05 04:57:10 +00:00
q += " " + token . Contents
2019-12-31 21:57:54 +00:00
case TokenColumn :
2017-09-03 04:50:31 +00:00
halves := strings . Split ( token . Contents , "." )
if len ( halves ) == 2 {
2019-06-05 04:57:10 +00:00
q += " `" + halves [ 0 ] + "`.`" + halves [ 1 ] + "`"
2017-09-03 04:50:31 +00:00
} else {
2019-06-05 04:57:10 +00:00
q += " `" + token . Contents + "`"
2017-09-03 04:50:31 +00:00
}
2019-12-31 21:57:54 +00:00
case TokenString :
2019-06-05 04:57:10 +00:00
q += " '" + token . Contents + "'"
2017-09-03 04:50:31 +00:00
default :
2019-06-05 04:57:10 +00:00
return q , errors . New ( "This token doesn't exist o_o" )
2017-06-25 09:56:39 +00:00
}
}
2019-06-05 04:57:10 +00:00
q += " AND"
2017-06-25 09:56:39 +00:00
}
2019-06-05 04:57:10 +00:00
q = q [ 0 : len ( q ) - 4 ]
2017-06-25 09:56:39 +00:00
}
2019-06-05 04:57:10 +00:00
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 ) {
2017-11-05 01:04:57 +00:00
if limit != "" {
2019-06-05 04:57:10 +00:00
q = " LIMIT " + limit
2017-06-25 09:56:39 +00:00
}
2019-06-05 04:57:10 +00:00
return q
2017-06-25 09:56:39 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) buildJoinColumns ( cols string ) ( q string ) {
for _ , col := range processColumns ( cols ) {
2019-02-23 06:29:19 +00:00
// TODO: Move the stirng and number logic to processColumns?
// TODO: Error if [0] doesn't exist
2019-12-31 21:57:54 +00:00
firstChar := col . Left [ 0 ]
2019-02-23 06:29:19 +00:00
if firstChar == '\'' {
2019-12-31 21:57:54 +00:00
col . Type = TokenString
2019-02-23 06:29:19 +00:00
} else {
_ , err := strconv . Atoi ( string ( firstChar ) )
if err == nil {
2019-12-31 21:57:54 +00:00
col . Type = TokenNumber
2019-02-23 06:29:19 +00:00
}
}
2017-06-19 08:06:54 +00:00
// Escape the column names, just in case we've used a reserved keyword
2019-12-31 21:57:54 +00:00
source := col . Left
if col . Table != "" {
source = "`" + col . Table + "`.`" + source + "`"
} else if col . Type != TokenFunc && col . Type != TokenNumber && col . Type != TokenSub && col . Type != TokenString {
2017-11-05 09:55:34 +00:00
source = "`" + source + "`"
2017-06-19 08:06:54 +00:00
}
2017-09-03 04:50:31 +00:00
2017-11-05 09:55:34 +00:00
var alias string
2019-12-31 21:57:54 +00:00
if col . Alias != "" {
alias = " AS `" + col . Alias + "`"
2017-06-19 08:06:54 +00:00
}
2019-06-05 04:57:10 +00:00
q += " " + source + alias + ","
2017-06-19 08:06:54 +00:00
}
2019-06-05 04:57:10 +00:00
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 ) {
whereStr , err := a . buildJoinWhere ( sel . Where )
2017-11-05 01:04:57 +00:00
if err != nil {
2017-11-05 03:58:19 +00:00
return "" , err
2017-06-19 08:06:54 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
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 )
2019-06-05 04:57:10 +00:00
q = strings . TrimSpace ( q )
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "insert" , q )
2019-06-05 04:57:10 +00:00
return q , nil
2017-06-19 08:06:54 +00:00
}
2020-01-01 04:15:11 +00:00
func ( a * MysqlAdapter ) SimpleCount ( name , table , where , limit string ) ( q string , err error ) {
2017-06-14 07:09:44 +00:00
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
2019-12-31 21:57:54 +00:00
whereStr , err := a . buildWhere ( where )
2017-11-05 01:04:57 +00:00
if err != nil {
return "" , err
2017-06-14 07:09:44 +00:00
}
2017-09-03 04:50:31 +00:00
2019-12-31 21:57:54 +00:00
q = "SELECT COUNT(*) FROM `" + table + "`" + whereStr + a . buildLimit ( limit )
2019-06-05 04:57:10 +00:00
q = strings . TrimSpace ( q )
2019-12-31 21:57:54 +00:00
a . pushStatement ( name , "select" , q )
2019-06-05 04:57:10 +00:00
return q , nil
2017-06-05 11:57:27 +00:00
}
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) Builder ( ) * prebuilder {
return & prebuilder { a }
2017-11-12 11:29:23 +00:00
}
2019-08-14 10:39:04 +00:00
func ( a * MysqlAdapter ) Write ( ) error {
2017-06-13 07:12:58 +00:00
var stmts , body string
2019-08-14 10:39:04 +00:00
for _ , name := range a . BufferOrder {
2017-10-14 07:39:22 +00:00
if name [ 0 ] == '_' {
continue
}
2019-08-14 10:39:04 +00:00
stmt := a . Buffer [ name ]
2017-10-16 07:32:58 +00:00
// ? - Table creation might be a little complex for Go to do outside a SQL file :(
if stmt . Type == "upsert" {
2017-11-05 09:55:34 +00:00
stmts += "\t" + name + " *qgen.MySQLUpsertCallback\n"
2017-10-16 07:32:58 +00:00
body += `
2018-02-26 09:07:00 +00:00
common . DebugLog ( "Preparing ` + name + ` statement." )
2017-11-05 09:55:34 +00:00
stmts . ` + name + ` , err = qgen . PrepareMySQLUpsertCallback ( db , "` + stmt.Contents + `" )
2017-10-16 07:32:58 +00:00
if err != nil {
2018-02-26 09:07:00 +00:00
log . Print ( "Error in ` + name + ` statement." )
2017-10-16 07:32:58 +00:00
return err
}
`
} else if stmt . Type != "create-table" {
2017-11-05 09:55:34 +00:00
stmts += "\t" + name + " *sql.Stmt\n"
2017-07-12 11:05:18 +00:00
body += `
2018-02-26 09:07:00 +00:00
common . DebugLog ( "Preparing ` + name + ` statement." )
2017-11-05 09:55:34 +00:00
stmts . ` + name + ` , err = db . Prepare ( "` + stmt.Contents + `" )
2017-06-13 07:12:58 +00:00
if err != nil {
2018-02-26 09:07:00 +00:00
log . Print ( "Error in ` + name + ` statement." )
2017-06-13 07:12:58 +00:00
return err
}
`
2017-07-12 11:05:18 +00:00
}
2017-06-13 07:12:58 +00:00
}
2017-09-03 04:50:31 +00:00
2017-11-05 09:55:34 +00:00
// TODO: Move these custom queries out of this file
2018-08-15 07:02:57 +00:00
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
import "log"
import "database/sql"
2018-10-27 03:21:02 +00:00
import "github.com/Azareal/Gosora/common"
//import "github.com/Azareal/Gosora/query_gen"
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 + `
2017-11-05 09:55:34 +00:00
getActivityFeedByWatcher * sql . Stmt
getActivityCountByWatcher * sql . Stmt
Mocks bool
}
2017-09-03 04:50:31 +00:00
// nolint
2017-07-12 11:05:18 +00:00
func _gen_mysql ( ) ( err error ) {
2018-02-19 04:26:01 +00:00
common . DebugLog ( "Building the generated statements" )
2017-06-13 07:12:58 +00:00
` + body + `
2017-06-05 11:57:27 +00:00
return nil
}
`
2017-09-03 04:50:31 +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
2019-08-14 10:39:04 +00:00
func ( a * MysqlAdapter ) pushStatement ( name string , stype string , querystr string ) {
2018-12-27 05:42:41 +00:00
if name == "" {
2018-02-10 15:07:21 +00:00
return
}
2019-08-14 10:39:04 +00:00
a . Buffer [ name ] = DBStmt { querystr , 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
2019-12-31 21:57:54 +00:00
func ( a * MysqlAdapter ) stringyType ( ctype string ) bool {
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
ctype = strings . ToLower ( ctype )
return ctype == "varchar" || ctype == "tinytext" || ctype == "text" || ctype == "mediumtext" || ctype == "longtext" || ctype == "char" || ctype == "datetime" || ctype == "timestamp" || ctype == "time" || ctype == "date"
}