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 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
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) GetName ( ) string {
2017-06-05 11:57:27 +00:00
return adapter . Name
}
2017-11-12 05:25:04 +00:00
func ( adapter * MysqlAdapter ) GetStmt ( name string ) DBStmt {
2017-06-13 07:12:58 +00:00
return adapter . Buffer [ name ]
}
2017-11-12 05:25:04 +00:00
func ( adapter * MysqlAdapter ) GetStmts ( ) map [ string ] DBStmt {
2017-06-13 07:12:58 +00:00
return adapter . Buffer
}
2018-08-29 01:37:57 +00:00
// TODO: Add an option to disable unix pipes
2018-03-31 05:25:27 +00:00
func ( adapter * MysqlAdapter ) BuildConn ( config map [ string ] string ) ( * sql . DB , error ) {
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" ]
}
db , err := sql . Open ( "mysql" , config [ "username" ] + dbpassword + "@unix(" + dbsocket + ")/" + config [ "name" ] + "?collation=" + dbCollation + "&parseTime=true" )
if err != nil {
return db , err
}
// Make sure that the connection is alive
return db , db . Ping ( )
}
2018-03-31 05:25:27 +00:00
// 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 ( )
}
func ( adapter * MysqlAdapter ) DbVersion ( ) string {
return "SELECT VERSION()"
}
2018-05-11 05:41:51 +00:00
func ( adapter * MysqlAdapter ) DropTable ( name string , table string ) ( string , error ) {
if name == "" {
return "" , errors . New ( "You need a name for this statement" )
}
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
querystr := "DROP TABLE IF EXISTS `" + table + "`;"
adapter . pushStatement ( name , "drop-table" , querystr )
return querystr , nil
}
2017-11-12 05:25:04 +00:00
func ( adapter * 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 name == "" {
return "" , errors . New ( "You need a name for this statement" )
}
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
var querystr = "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 {
2018-05-27 09:36:35 +00:00
column , size , end := adapter . parseColumn ( column )
2017-09-03 04:50:31 +00:00
querystr += "\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 {
2017-07-12 11:05:18 +00:00
querystr += "\n\t" + key . Type
if key . Type != "unique" {
querystr += " key"
}
querystr += "("
2017-09-03 04:50:31 +00:00
for _ , column := range strings . Split ( key . Columns , "," ) {
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
querystr += "`" + column + "`,"
}
2017-09-03 04:50:31 +00:00
querystr = querystr [ 0 : len ( querystr ) - 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
querystr = querystr [ 0 : len ( querystr ) - 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 != "" {
querystr += " CHARSET=" + charset
}
if collation != "" {
querystr += " COLLATE " + collation
}
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "create-table" , querystr + ";" )
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
return querystr + ";" , nil
}
2018-05-27 09:36:35 +00:00
func ( adapter * MysqlAdapter ) parseColumn ( column DBTableColumn ) ( col DBTableColumn , size string , end string ) {
// Make it easier to support Cassandra in the future
if column . Type == "createdAt" {
column . Type = "datetime"
} 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 "
if adapter . stringyType ( column . Type ) && column . Default != "''" {
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
func ( adapter * MysqlAdapter ) AddColumn ( name string , table string , column DBTableColumn ) ( string , error ) {
if name == "" {
return "" , errors . New ( "You need a name for this statement" )
}
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
column , size , end := adapter . parseColumn ( column )
querystr := "ALTER TABLE `" + table + "` ADD COLUMN " + "`" + column . Name + "` " + column . Type + size + end + ";"
adapter . pushStatement ( name , "add-column" , querystr )
return querystr , nil
}
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) SimpleInsert ( name string , table string , columns string , fields string ) ( string , error ) {
2017-06-05 11:57:27 +00:00
if name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
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
2018-04-23 21:08:31 +00:00
var querystr = "INSERT INTO `" + table + "`("
2018-04-22 12:33:56 +00:00
if columns != "" {
2018-04-23 21:08:31 +00:00
querystr += adapter . buildColumns ( columns ) + ") VALUES ("
2018-04-22 12:33:56 +00:00
for _ , field := range processFields ( fields ) {
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 ) + "'"
}
querystr += field . Name + ","
2017-10-14 07:39:22 +00:00
}
2018-04-23 21:08:31 +00:00
querystr = querystr [ 0 : len ( querystr ) - 1 ]
} else {
querystr += ") VALUES ("
2017-06-05 11:57:27 +00:00
}
2018-04-23 21:08:31 +00:00
querystr += ")"
2017-09-03 04:50:31 +00:00
2017-11-05 09:55:34 +00:00
adapter . pushStatement ( name , "insert" , querystr )
return querystr , nil
2017-06-05 11:57:27 +00:00
}
2017-11-05 01:04:57 +00:00
func ( adapter * MysqlAdapter ) buildColumns ( columns string ) ( querystr 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
for _ , column := range processColumns ( columns ) {
if column . Type == "function" {
querystr += column . Left + ","
} else {
querystr += "`" + column . Left + "`,"
}
}
return querystr [ 0 : len ( querystr ) - 1 ]
}
2017-10-16 07:32:58 +00:00
// ! DEPRECATED
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) SimpleReplace ( name string , table string , columns string , fields string ) ( string , error ) {
2017-06-10 07:58:15 +00:00
if name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
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
2017-11-05 01:04:57 +00:00
var querystr = "REPLACE INTO `" + table + "`(" + adapter . 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 ) {
2017-06-10 07:58:15 +00:00
querystr += field . Name + ","
}
2017-09-03 04:50:31 +00:00
querystr = querystr [ 0 : len ( querystr ) - 1 ]
adapter . pushStatement ( name , "replace" , querystr + ")" )
2017-06-13 08:56:48 +00:00
return querystr + ")" , nil
2017-06-10 07:58:15 +00:00
}
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) SimpleUpsert ( name string , table string , columns string , fields string , where string ) ( string , error ) {
2017-10-16 07:32:58 +00:00
if name == "" {
return "" , errors . New ( "You need a name for this statement" )
}
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" )
}
var querystr = "INSERT INTO `" + table + "`("
var parsedFields = processFields ( fields )
var insertColumns string
var insertValues string
var setBit = ") ON DUPLICATE KEY UPDATE "
for columnID , column := range processColumns ( columns ) {
field := parsedFields [ columnID ]
if column . Type == "function" {
insertColumns += column . Left + ","
insertValues += field . Name + ","
setBit += column . Left + " = " + field . Name + " AND "
} else {
insertColumns += "`" + column . Left + "`,"
insertValues += field . Name + ","
setBit += "`" + column . Left + "` = " + field . Name + " AND "
}
}
insertColumns = insertColumns [ 0 : len ( insertColumns ) - 1 ]
insertValues = insertValues [ 0 : len ( insertValues ) - 1 ]
insertColumns += ") VALUES (" + insertValues
setBit = setBit [ 0 : len ( setBit ) - 5 ]
querystr += insertColumns + setBit
adapter . pushStatement ( name , "upsert" , querystr )
return querystr , nil
}
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) SimpleUpdate ( name string , table string , set string , where string ) ( string , error ) {
2017-06-07 10:07:40 +00:00
if name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
2017-06-07 10:07:40 +00:00
}
if 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
}
if 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
}
2017-09-03 04:50:31 +00:00
var querystr = "UPDATE `" + table + "` SET "
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 _ , item := range processSet ( set ) {
2017-06-07 10:07:40 +00:00
querystr += "`" + item . Column + "` ="
for _ , token := range item . Expr {
2017-09-03 04:50:31 +00:00
switch token . Type {
2018-03-31 05:25:27 +00:00
case "function" , "operator" , "number" , "substitute" , "or" :
2017-09-03 04:50:31 +00:00
querystr += " " + token . Contents
case "column" :
querystr += " `" + token . Contents + "`"
case "string" :
querystr += " '" + token . Contents + "'"
2017-06-07 10:07:40 +00:00
}
}
querystr += ","
}
2017-09-03 04:50:31 +00:00
querystr = querystr [ 0 : len ( querystr ) - 1 ]
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildWhere ( where )
if err != nil {
return querystr , err
2017-06-07 10:07:40 +00:00
}
2017-11-05 01:04:57 +00:00
querystr += whereStr
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "update" , querystr )
2017-06-13 08:56:48 +00:00
return querystr , nil
2017-06-05 11:57:27 +00:00
}
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) SimpleDelete ( name string , table string , where string ) ( string , error ) {
2017-06-12 09:03:14 +00:00
if name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
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
}
2017-09-03 04:50:31 +00:00
var querystr = "DELETE FROM `" + table + "` WHERE"
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 {
2018-03-31 05:25:27 +00:00
case "function" , "operator" , "number" , "substitute" , "or" :
2017-09-03 04:50:31 +00:00
querystr += " " + token . Contents
case "column" :
querystr += " `" + token . Contents + "`"
case "string" :
querystr += " '" + token . Contents + "'"
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
}
2017-06-19 08:06:54 +00:00
querystr += " AND"
2017-06-12 09:03:14 +00:00
}
2017-09-03 04:50:31 +00:00
querystr = strings . TrimSpace ( querystr [ 0 : len ( querystr ) - 4 ] )
adapter . pushStatement ( name , "delete" , querystr )
2017-06-13 08:56:48 +00:00
return querystr , 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
func ( adapter * MysqlAdapter ) Purge ( name string , table string ) ( string , error ) {
2017-06-12 09:03:14 +00:00
if name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
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
}
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "purge" , "DELETE FROM `" + table + "`" )
2017-06-13 08:56:48 +00:00
return "DELETE FROM `" + table + "`" , nil
2017-06-12 09:03:14 +00:00
}
2017-11-05 01:04:57 +00:00
func ( adapter * MysqlAdapter ) buildWhere ( where string ) ( querystr string , err error ) {
2018-01-03 07:46:18 +00:00
if len ( where ) == 0 {
return "" , nil
}
querystr = " WHERE"
for _ , loc := range processWhere ( where ) {
for _ , token := range loc . Expr {
switch token . Type {
2018-03-31 05:25:27 +00:00
case "function" , "operator" , "number" , "substitute" , "or" :
2018-01-03 07:46:18 +00:00
querystr += " " + token . Contents
case "column" :
querystr += " `" + token . Contents + "`"
case "string" :
querystr += " '" + token . Contents + "'"
default :
return querystr , errors . New ( "This token doesn't exist o_o" )
}
}
querystr += " AND"
}
return querystr [ 0 : len ( querystr ) - 4 ] , nil
}
// The new version of buildWhere() currently only used in ComplexSelect for complex OO builder queries
func ( adapter * MysqlAdapter ) buildFlexiWhere ( where string , dateCutoff * dateCutoff ) ( querystr string , err error ) {
if len ( where ) == 0 && dateCutoff == nil {
return "" , nil
}
querystr = " WHERE"
if dateCutoff != nil {
querystr += " " + dateCutoff . Column + " BETWEEN (UTC_TIMESTAMP() - interval " + strconv . Itoa ( dateCutoff . Quantity ) + " " + dateCutoff . Unit + ") AND UTC_TIMESTAMP() AND"
}
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 {
2018-03-31 05:25:27 +00:00
case "function" , "operator" , "number" , "substitute" , "or" :
2017-09-03 04:50:31 +00:00
querystr += " " + token . Contents
case "column" :
querystr += " `" + token . Contents + "`"
case "string" :
querystr += " '" + token . Contents + "'"
default :
2017-11-05 01:04:57 +00:00
return querystr , 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
}
2017-06-19 08:06:54 +00:00
querystr += " AND"
2017-06-05 11:57:27 +00:00
}
}
2018-01-03 07:46:18 +00:00
return querystr [ 0 : len ( querystr ) - 4 ] , nil
2017-11-05 01:04:57 +00:00
}
2017-09-03 04:50:31 +00:00
2017-11-05 01:04:57 +00:00
func ( adapter * MysqlAdapter ) buildOrderby ( orderby string ) ( querystr string ) {
2017-06-05 11:57:27 +00:00
if len ( orderby ) != 0 {
2017-11-05 09:55:34 +00:00
querystr = " 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
2018-04-22 12:33:56 +00:00
querystr += "`" + strings . Replace ( column . Column , "." , "`.`" , - 1 ) + "` " + strings . ToUpper ( column . Order ) + ","
2017-06-05 11:57:27 +00:00
}
2017-09-03 04:50:31 +00:00
querystr = querystr [ 0 : len ( querystr ) - 1 ]
2017-06-05 11:57:27 +00:00
}
2017-11-05 01:04:57 +00:00
return querystr
}
2017-09-03 04:50:31 +00:00
2017-11-05 01:04:57 +00:00
func ( adapter * MysqlAdapter ) SimpleSelect ( name string , table string , columns string , where string , orderby string , limit string ) ( string , error ) {
if name == "" {
return "" , errors . New ( "You need a name for this statement" )
2017-06-15 11:40:35 +00:00
}
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" )
}
var querystr = "SELECT "
// 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 ) , "," ) {
2017-11-05 01:04:57 +00:00
querystr += "`" + strings . TrimSpace ( column ) + "`,"
}
querystr = querystr [ 0 : len ( querystr ) - 1 ]
whereStr , err := adapter . buildWhere ( where )
if err != nil {
return querystr , err
}
querystr += " FROM `" + table + "`" + whereStr + adapter . buildOrderby ( orderby ) + adapter . buildLimit ( limit )
2017-09-03 04:50:31 +00:00
2017-06-13 08:56:48 +00:00
querystr = strings . TrimSpace ( querystr )
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "select" , querystr )
2017-06-13 08:56:48 +00:00
return querystr , nil
2017-06-05 11:57:27 +00:00
}
2018-01-21 11:17:43 +00:00
func ( adapter * MysqlAdapter ) ComplexSelect ( preBuilder * selectPrebuilder ) ( out string , err error ) {
2018-01-03 07:46:18 +00:00
if preBuilder . name == "" {
return "" , errors . New ( "You need a name for this statement" )
}
if preBuilder . table == "" {
return "" , errors . New ( "You need a name for this table" )
}
if len ( preBuilder . columns ) == 0 {
return "" , errors . New ( "No columns found for ComplexSelect" )
}
var querystr = "SELECT "
// Slice up the user friendly strings into something easier to process
for _ , column := range strings . Split ( strings . TrimSpace ( preBuilder . columns ) , "," ) {
querystr += "`" + strings . TrimSpace ( column ) + "`,"
}
querystr = querystr [ 0 : len ( querystr ) - 1 ]
2018-01-21 11:17:43 +00:00
var whereStr string
// TODO: Let callers have a Where() and a InQ()
if preBuilder . inChain != nil {
whereStr , err = adapter . ComplexSelect ( preBuilder . inChain )
if err != nil {
return querystr , err
}
whereStr = " WHERE `" + preBuilder . inColumn + "` IN(" + whereStr + ")"
} else {
whereStr , err = adapter . buildFlexiWhere ( preBuilder . where , preBuilder . dateCutoff )
if err != nil {
return querystr , err
}
2018-01-03 07:46:18 +00:00
}
querystr += " FROM `" + preBuilder . table + "`" + whereStr + adapter . buildOrderby ( preBuilder . orderby ) + adapter . buildLimit ( preBuilder . limit )
querystr = strings . TrimSpace ( querystr )
adapter . pushStatement ( preBuilder . name , "select" , querystr )
return querystr , nil
}
2017-10-30 09:57:08 +00:00
func ( adapter * 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 name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
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
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildJoinWhere ( where )
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
2017-11-05 03:58:19 +00:00
var querystr = "SELECT" + adapter . buildJoinColumns ( columns ) + " FROM `" + table1 + "` LEFT JOIN `" + table2 + "` ON " + adapter . buildJoiners ( joiners ) + whereStr + adapter . buildOrderby ( orderby ) + adapter . buildLimit ( limit )
2017-09-03 04:50:31 +00:00
2017-06-13 08:56:48 +00:00
querystr = strings . TrimSpace ( querystr )
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "select" , querystr )
2017-06-13 08:56:48 +00:00
return querystr , nil
2017-06-12 09:03:14 +00:00
}
2017-10-30 09:57:08 +00:00
func ( adapter * 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 name == "" {
2017-06-13 08:56:48 +00:00
return "" , errors . New ( "You need a name for this statement" )
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
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildJoinWhere ( where )
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
2017-11-05 03:58:19 +00:00
var querystr = "SELECT " + adapter . buildJoinColumns ( columns ) + " FROM `" + table1 + "` INNER JOIN `" + table2 + "` ON " + adapter . buildJoiners ( joiners ) + whereStr + adapter . buildOrderby ( orderby ) + adapter . buildLimit ( limit )
2017-09-03 04:50:31 +00:00
2017-06-13 08:56:48 +00:00
querystr = strings . TrimSpace ( querystr )
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "select" , querystr )
2017-06-14 07:09:44 +00:00
return querystr , nil
}
2017-11-12 05:25:04 +00:00
func ( adapter * MysqlAdapter ) SimpleInsertSelect ( name string , ins DBInsert , sel DBSelect ) ( string , error ) {
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildWhere ( sel . Where )
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
2017-11-05 03:58:19 +00:00
var querystr = "INSERT INTO `" + ins . Table + "`(" + adapter . buildColumns ( ins . Columns ) + ") SELECT" + adapter . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table + "`" + whereStr + adapter . buildOrderby ( sel . Orderby ) + adapter . buildLimit ( sel . Limit )
2017-09-03 04:50:31 +00:00
2017-06-19 08:06:54 +00:00
querystr = strings . TrimSpace ( querystr )
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "insert" , querystr )
2017-06-19 08:06:54 +00:00
return querystr , nil
}
2017-11-12 05:25:04 +00:00
func ( adapter * MysqlAdapter ) SimpleInsertLeftJoin ( name string , ins DBInsert , sel DBJoin ) ( string , error ) {
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildJoinWhere ( sel . Where )
if err != nil {
2017-11-05 03:58:19 +00:00
return "" , err
2017-11-05 01:04:57 +00:00
}
2017-11-05 03:58:19 +00:00
var querystr = "INSERT INTO `" + ins . Table + "`(" + adapter . buildColumns ( ins . Columns ) + ") SELECT" + adapter . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table1 + "` LEFT JOIN `" + sel . Table2 + "` ON " + adapter . buildJoiners ( sel . Joiners ) + whereStr + adapter . buildOrderby ( sel . Orderby ) + adapter . buildLimit ( sel . Limit )
2017-11-05 01:04:57 +00:00
querystr = strings . TrimSpace ( querystr )
adapter . pushStatement ( name , "insert" , querystr )
return querystr , nil
}
// TODO: Make this more consistent with the other build* methods?
func ( adapter * MysqlAdapter ) buildJoiners ( joiners string ) ( querystr string ) {
for _ , joiner := range processJoiner ( joiners ) {
2017-06-25 09:56:39 +00:00
querystr += "`" + joiner . LeftTable + "`.`" + joiner . LeftColumn + "` " + joiner . Operator + " `" + joiner . RightTable + "`.`" + joiner . RightColumn + "` AND "
}
2017-11-05 01:04:57 +00:00
// Remove the trailing AND
return querystr [ 0 : len ( querystr ) - 4 ]
}
2017-09-03 04:50:31 +00:00
2017-11-05 01:04:57 +00:00
// Add support for BETWEEN x.x
func ( adapter * MysqlAdapter ) buildJoinWhere ( where string ) ( querystr string , err error ) {
if len ( where ) != 0 {
2017-11-05 09:55:34 +00:00
querystr = " 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 {
2018-03-31 05:25:27 +00:00
case "function" , "operator" , "number" , "substitute" , "or" :
2017-09-03 04:50:31 +00:00
querystr += " " + token . Contents
case "column" :
halves := strings . Split ( token . Contents , "." )
if len ( halves ) == 2 {
querystr += " `" + halves [ 0 ] + "`.`" + halves [ 1 ] + "`"
} else {
querystr += " `" + token . Contents + "`"
}
case "string" :
querystr += " '" + token . Contents + "'"
default :
2017-11-05 01:04:57 +00:00
return querystr , errors . New ( "This token doesn't exist o_o" )
2017-06-25 09:56:39 +00:00
}
}
querystr += " AND"
}
2017-09-03 04:50:31 +00:00
querystr = querystr [ 0 : len ( querystr ) - 4 ]
2017-06-25 09:56:39 +00:00
}
2017-11-05 01:04:57 +00:00
return querystr , nil
}
2017-09-03 04:50:31 +00:00
2017-11-05 01:04:57 +00:00
func ( adapter * MysqlAdapter ) buildLimit ( limit string ) ( querystr string ) {
if limit != "" {
2017-11-05 09:55:34 +00:00
querystr = " LIMIT " + limit
2017-06-25 09:56:39 +00:00
}
2017-11-05 01:04:57 +00:00
return querystr
2017-06-25 09:56:39 +00:00
}
2017-11-05 03:58:19 +00:00
func ( adapter * MysqlAdapter ) buildJoinColumns ( columns string ) ( querystr string ) {
for _ , column := range processColumns ( columns ) {
2017-06-19 08:06:54 +00:00
// Escape the column names, just in case we've used a reserved keyword
2017-11-05 09:55:34 +00:00
var source = column . Left
2017-06-19 08:06:54 +00:00
if column . Table != "" {
2017-11-05 09:55:34 +00:00
source = "`" + column . Table + "`.`" + source + "`"
} else if column . Type != "function" {
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
2017-06-19 08:06:54 +00:00
if column . Alias != "" {
alias = " AS `" + column . Alias + "`"
}
querystr += " " + source + alias + ","
}
2017-11-05 03:58:19 +00:00
return querystr [ 0 : len ( querystr ) - 1 ]
}
2017-09-03 04:50:31 +00:00
2017-11-12 05:25:04 +00:00
func ( adapter * MysqlAdapter ) SimpleInsertInnerJoin ( name string , ins DBInsert , sel DBJoin ) ( string , error ) {
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildJoinWhere ( sel . Where )
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
2017-11-05 03:58:19 +00:00
var querystr = "INSERT INTO `" + ins . Table + "`(" + adapter . buildColumns ( ins . Columns ) + ") SELECT" + adapter . buildJoinColumns ( sel . Columns ) + " FROM `" + sel . Table1 + "` INNER JOIN `" + sel . Table2 + "` ON " + adapter . buildJoiners ( sel . Joiners ) + whereStr + adapter . buildOrderby ( sel . Orderby ) + adapter . buildLimit ( sel . Limit )
2017-09-03 04:50:31 +00:00
2017-06-19 08:06:54 +00:00
querystr = strings . TrimSpace ( querystr )
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "insert" , querystr )
2017-06-19 08:06:54 +00:00
return querystr , nil
}
2017-11-05 01:04:57 +00:00
func ( adapter * MysqlAdapter ) SimpleCount ( name string , table string , where string , limit string ) ( querystr string , err error ) {
2017-06-14 07:09:44 +00:00
if name == "" {
return "" , errors . New ( "You need a name for this statement" )
}
if table == "" {
return "" , errors . New ( "You need a name for this table" )
}
2017-09-03 04:50:31 +00:00
2017-11-05 01:04:57 +00:00
whereStr , err := adapter . buildWhere ( where )
if err != nil {
return "" , err
2017-06-14 07:09:44 +00:00
}
2017-09-03 04:50:31 +00:00
2017-11-05 03:58:19 +00:00
querystr = "SELECT COUNT(*) AS `count` FROM `" + table + "`" + whereStr + adapter . buildLimit ( limit )
2017-06-14 07:09:44 +00:00
querystr = strings . TrimSpace ( querystr )
2017-09-03 04:50:31 +00:00
adapter . pushStatement ( name , "select" , querystr )
2017-06-13 08:56:48 +00:00
return querystr , nil
2017-06-05 11:57:27 +00:00
}
2017-11-13 00:31:46 +00:00
func ( adapter * MysqlAdapter ) Builder ( ) * prebuilder {
return & prebuilder { adapter }
2017-11-12 11:29:23 +00:00
}
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) Write ( ) error {
2017-06-13 07:12:58 +00:00
var stmts , body string
for _ , name := range adapter . BufferOrder {
2017-10-14 07:39:22 +00:00
if name [ 0 ] == '_' {
continue
}
2017-07-12 11:05:18 +00:00
stmt := adapter . 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"
2017-11-11 04:06:16 +00:00
import "./common"
2017-10-21 00:27:47 +00:00
//import "./query_gen/lib"
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
todaysPostCount * sql . Stmt
todaysTopicCount * sql . Stmt
2018-06-06 00:21:22 +00:00
todaysTopicCountByForum * sql . Stmt
2017-11-05 09:55:34 +00:00
todaysNewUserCount * 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
2017-10-30 09:57:08 +00:00
func ( adapter * MysqlAdapter ) pushStatement ( name string , stype string , querystr string ) {
2018-02-10 15:07:21 +00:00
if name [ 0 ] == '_' {
return
}
2017-11-12 05:25:04 +00:00
adapter . Buffer [ name ] = DBStmt { querystr , stype }
2017-09-03 04:50:31 +00:00
adapter . BufferOrder = append ( adapter . 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
2017-10-30 09:57:08 +00:00
func ( adapter * 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"
}