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
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Query Generator Library
|
|
|
|
* WIP Under Construction
|
2019-02-23 06:29:19 +00:00
|
|
|
* Copyright Azareal 2017 - 2020
|
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
|
|
|
*
|
|
|
|
*/
|
2017-06-13 07:12:58 +00:00
|
|
|
package qgen
|
2017-06-12 09:03:14 +00:00
|
|
|
|
2017-10-16 07:32:58 +00:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
2017-06-12 09:03:14 +00:00
|
|
|
|
2019-02-23 06:29:19 +00:00
|
|
|
// TODO: Add support for numbers and strings?
|
2017-11-12 05:25:04 +00:00
|
|
|
func processColumns(colstr string) (columns []DBColumn) {
|
2017-06-12 09:03:14 +00:00
|
|
|
if colstr == "" {
|
|
|
|
return columns
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
colstr = strings.Replace(colstr, " as ", " AS ", -1)
|
|
|
|
for _, segment := range strings.Split(colstr, ",") {
|
2017-11-12 05:25:04 +00:00
|
|
|
var outcol DBColumn
|
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
|
|
|
dotHalves := strings.Split(strings.TrimSpace(segment), ".")
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
var halves []string
|
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
|
|
|
if len(dotHalves) == 2 {
|
|
|
|
outcol.Table = dotHalves[0]
|
|
|
|
halves = strings.Split(dotHalves[1], " AS ")
|
2017-06-12 09:03:14 +00:00
|
|
|
} else {
|
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
|
|
|
halves = strings.Split(dotHalves[0], " AS ")
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
halves[0] = strings.TrimSpace(halves[0])
|
|
|
|
if len(halves) == 2 {
|
|
|
|
outcol.Alias = strings.TrimSpace(halves[1])
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
if halves[0][len(halves[0])-1] == ')' {
|
2017-06-12 09:03:14 +00:00
|
|
|
outcol.Type = "function"
|
2017-06-19 08:06:54 +00:00
|
|
|
} else if halves[0] == "?" {
|
|
|
|
outcol.Type = "substitute"
|
2017-06-12 09:03:14 +00:00
|
|
|
} else {
|
|
|
|
outcol.Type = "column"
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
outcol.Left = halves[0]
|
2017-09-03 04:50:31 +00:00
|
|
|
columns = append(columns, outcol)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return columns
|
|
|
|
}
|
|
|
|
|
2017-10-16 07:32:58 +00:00
|
|
|
// TODO: Allow order by statements without a direction
|
2017-11-12 05:25:04 +00:00
|
|
|
func processOrderby(orderstr string) (order []DBOrder) {
|
2017-06-12 09:03:14 +00:00
|
|
|
if orderstr == "" {
|
|
|
|
return order
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
for _, segment := range strings.Split(orderstr, ",") {
|
2017-11-12 05:25:04 +00:00
|
|
|
var outorder DBOrder
|
2017-09-03 04:50:31 +00:00
|
|
|
halves := strings.Split(strings.TrimSpace(segment), " ")
|
2017-06-12 09:03:14 +00:00
|
|
|
if len(halves) != 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
outorder.Column = halves[0]
|
|
|
|
outorder.Order = strings.ToLower(halves[1])
|
2017-09-03 04:50:31 +00:00
|
|
|
order = append(order, outorder)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return order
|
|
|
|
}
|
|
|
|
|
2017-11-12 05:25:04 +00:00
|
|
|
func processJoiner(joinstr string) (joiner []DBJoiner) {
|
2017-06-12 09:03:14 +00:00
|
|
|
if joinstr == "" {
|
|
|
|
return joiner
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
joinstr = strings.Replace(joinstr, " on ", " ON ", -1)
|
|
|
|
joinstr = strings.Replace(joinstr, " and ", " AND ", -1)
|
|
|
|
for _, segment := range strings.Split(joinstr, " AND ") {
|
2017-11-12 05:25:04 +00:00
|
|
|
var outjoin DBJoiner
|
2017-06-12 09:03:14 +00:00
|
|
|
var parseOffset int
|
|
|
|
var left, right string
|
2017-09-03 04:50:31 +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
|
|
|
left, parseOffset = getIdentifier(segment, parseOffset)
|
|
|
|
outjoin.Operator, parseOffset = getOperator(segment, parseOffset+1)
|
|
|
|
right, parseOffset = getIdentifier(segment, parseOffset+1)
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-11-10 00:16:15 +00:00
|
|
|
leftColumn := strings.Split(left, ".")
|
|
|
|
rightColumn := strings.Split(right, ".")
|
|
|
|
outjoin.LeftTable = strings.TrimSpace(leftColumn[0])
|
|
|
|
outjoin.RightTable = strings.TrimSpace(rightColumn[0])
|
|
|
|
outjoin.LeftColumn = strings.TrimSpace(leftColumn[1])
|
|
|
|
outjoin.RightColumn = strings.TrimSpace(rightColumn[1])
|
2017-09-03 04:50:31 +00:00
|
|
|
|
|
|
|
joiner = append(joiner, outjoin)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return joiner
|
|
|
|
}
|
|
|
|
|
2017-11-13 00:31:46 +00:00
|
|
|
func (where *DBWhere) parseNumber(segment string, i int) int {
|
2017-11-12 11:29:23 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if '0' <= char && char <= '9' {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
|
|
|
i--
|
2017-11-13 00:31:46 +00:00
|
|
|
where.Expr = append(where.Expr, DBToken{buffer, "number"})
|
2017-11-12 11:29:23 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2017-11-13 00:31:46 +00:00
|
|
|
func (where *DBWhere) parseColumn(segment string, i int) int {
|
2017-11-12 11:29:23 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
2017-11-13 00:36:31 +00:00
|
|
|
switch {
|
|
|
|
case ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '.' || char == '_':
|
2017-11-12 11:29:23 +00:00
|
|
|
buffer += string(char)
|
2017-11-13 00:36:31 +00:00
|
|
|
case char == '(':
|
2017-11-13 00:31:46 +00:00
|
|
|
return where.parseFunction(segment, buffer, i)
|
2017-11-13 00:36:31 +00:00
|
|
|
default:
|
2017-11-12 11:29:23 +00:00
|
|
|
i--
|
2017-11-13 00:31:46 +00:00
|
|
|
where.Expr = append(where.Expr, DBToken{buffer, "column"})
|
2017-11-12 11:29:23 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2017-11-13 00:31:46 +00:00
|
|
|
func (where *DBWhere) parseFunction(segment string, buffer string, i int) int {
|
2017-11-12 11:29:23 +00:00
|
|
|
var preI = i
|
|
|
|
i = skipFunctionCall(segment, i-1)
|
|
|
|
buffer += segment[preI:i] + string(segment[i])
|
2017-11-13 00:31:46 +00:00
|
|
|
where.Expr = append(where.Expr, DBToken{buffer, "function"})
|
2017-11-12 11:29:23 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2017-11-13 00:31:46 +00:00
|
|
|
func (where *DBWhere) parseString(segment string, i int) int {
|
|
|
|
var buffer string
|
|
|
|
i++
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if char != '\'' {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
|
|
|
where.Expr = append(where.Expr, DBToken{buffer, "string"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (where *DBWhere) parseOperator(segment string, i int) int {
|
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if isOpByte(char) {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
|
|
|
i--
|
|
|
|
where.Expr = append(where.Expr, DBToken{buffer, "operator"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Make this case insensitive
|
|
|
|
func normalizeAnd(in string) string {
|
2018-03-31 05:25:27 +00:00
|
|
|
in = strings.Replace(in, " and ", " AND ", -1)
|
|
|
|
return strings.Replace(in, " && ", " AND ", -1)
|
|
|
|
}
|
|
|
|
func normalizeOr(in string) string {
|
|
|
|
in = strings.Replace(in, " or ", " OR ", -1)
|
|
|
|
return strings.Replace(in, " || ", " OR ", -1)
|
2017-11-13 00:31:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Write tests for this
|
2017-11-12 05:25:04 +00:00
|
|
|
func processWhere(wherestr string) (where []DBWhere) {
|
2017-06-12 09:03:14 +00:00
|
|
|
if wherestr == "" {
|
|
|
|
return where
|
|
|
|
}
|
2017-11-13 00:31:46 +00:00
|
|
|
wherestr = normalizeAnd(wherestr)
|
2018-03-31 05:25:27 +00:00
|
|
|
wherestr = normalizeOr(wherestr)
|
2017-09-03 04:50:31 +00:00
|
|
|
|
|
|
|
for _, segment := range strings.Split(wherestr, " AND ") {
|
2017-11-12 11:29:23 +00:00
|
|
|
var tmpWhere = &DBWhere{[]DBToken{}}
|
2017-06-19 08:06:54 +00:00
|
|
|
segment += ")"
|
|
|
|
for i := 0; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
|
|
|
case '0' <= char && char <= '9':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpWhere.parseNumber(segment, i)
|
2018-03-31 05:25:27 +00:00
|
|
|
// TODO: Sniff the third byte offset from char or it's non-existent to avoid matching uppercase strings which start with OR
|
|
|
|
case char == 'O' && (i+1) < len(segment) && segment[i+1] == 'R':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"OR", "or"})
|
|
|
|
i += 1
|
2017-11-13 05:22:37 +00:00
|
|
|
case ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpWhere.parseColumn(segment, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
case char == '\'':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpWhere.parseString(segment, i)
|
2018-03-31 05:25:27 +00:00
|
|
|
case char == ')' && i < (len(segment)-1):
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{")", "operator"})
|
2017-11-13 05:22:37 +00:00
|
|
|
case isOpByte(char):
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpWhere.parseOperator(segment, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
case char == '?':
|
2017-11-13 00:31:46 +00:00
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"?", "substitute"})
|
2017-06-19 08:06:54 +00:00
|
|
|
}
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2017-11-12 11:29:23 +00:00
|
|
|
where = append(where, *tmpWhere)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return where
|
|
|
|
}
|
|
|
|
|
2017-11-13 00:31:46 +00:00
|
|
|
func (setter *DBSetter) parseNumber(segment string, i int) int {
|
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if '0' <= char && char <= '9' {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
|
|
|
setter.Expr = append(setter.Expr, DBToken{buffer, "number"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (setter *DBSetter) parseColumn(segment string, i int) int {
|
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
|
|
|
case ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_':
|
2017-11-13 00:31:46 +00:00
|
|
|
buffer += string(char)
|
2017-11-13 05:22:37 +00:00
|
|
|
case char == '(':
|
2017-11-13 00:31:46 +00:00
|
|
|
return setter.parseFunction(segment, buffer, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
default:
|
2017-11-13 00:31:46 +00:00
|
|
|
i--
|
|
|
|
setter.Expr = append(setter.Expr, DBToken{buffer, "column"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (setter *DBSetter) parseFunction(segment string, buffer string, i int) int {
|
|
|
|
var preI = i
|
|
|
|
i = skipFunctionCall(segment, i-1)
|
|
|
|
buffer += segment[preI:i] + string(segment[i])
|
|
|
|
setter.Expr = append(setter.Expr, DBToken{buffer, "function"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (setter *DBSetter) parseString(segment string, i int) int {
|
|
|
|
var buffer string
|
|
|
|
i++
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if char != '\'' {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
|
|
|
setter.Expr = append(setter.Expr, DBToken{buffer, "string"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func (setter *DBSetter) parseOperator(segment string, i int) int {
|
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if isOpByte(char) {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
|
|
|
i--
|
|
|
|
setter.Expr = append(setter.Expr, DBToken{buffer, "operator"})
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2017-11-12 05:25:04 +00:00
|
|
|
func processSet(setstr string) (setter []DBSetter) {
|
2017-06-12 09:03:14 +00:00
|
|
|
if setstr == "" {
|
|
|
|
return setter
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
// First pass, splitting the string by commas while ignoring the innards of functions
|
|
|
|
var setset []string
|
|
|
|
var buffer string
|
2017-09-03 04:50:31 +00:00
|
|
|
var lastItem int
|
2017-06-12 09:03:14 +00:00
|
|
|
setstr += ","
|
2017-09-03 04:50:31 +00:00
|
|
|
for i := 0; i < len(setstr); i++ {
|
2017-06-12 09:03:14 +00:00
|
|
|
if setstr[i] == '(' {
|
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
|
|
|
i = skipFunctionCall(setstr, i-1)
|
2017-09-03 04:50:31 +00:00
|
|
|
setset = append(setset, setstr[lastItem:i+1])
|
2017-06-12 09:03:14 +00:00
|
|
|
buffer = ""
|
2017-09-03 04:50:31 +00:00
|
|
|
lastItem = i + 2
|
2017-06-12 09:03:14 +00:00
|
|
|
} else if setstr[i] == ',' && buffer != "" {
|
2017-09-03 04:50:31 +00:00
|
|
|
setset = append(setset, buffer)
|
2017-06-12 09:03:14 +00:00
|
|
|
buffer = ""
|
2017-09-03 04:50:31 +00:00
|
|
|
lastItem = i + 1
|
2017-06-12 09:03:14 +00:00
|
|
|
} else if (setstr[i] > 32) && setstr[i] != ',' && setstr[i] != ')' {
|
|
|
|
buffer += string(setstr[i])
|
|
|
|
}
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
// Second pass. Break this setitem into manageable chunks
|
|
|
|
for _, setitem := range setset {
|
2017-09-03 04:50:31 +00:00
|
|
|
halves := strings.Split(setitem, "=")
|
2017-06-12 09:03:14 +00:00
|
|
|
if len(halves) != 2 {
|
|
|
|
continue
|
|
|
|
}
|
2017-11-13 00:31:46 +00:00
|
|
|
tmpSetter := &DBSetter{Column: strings.TrimSpace(halves[0])}
|
2017-11-12 11:29:23 +00:00
|
|
|
segment := halves[1] + ")"
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2017-11-12 11:29:23 +00:00
|
|
|
for i := 0; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
|
|
|
case '0' <= char && char <= '9':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseNumber(segment, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
case ('a' <= char && char <= 'z') || ('A' <= char && char <= 'Z') || char == '_':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseColumn(segment, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
case char == '\'':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseString(segment, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
case isOpByte(char):
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseOperator(segment, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
case char == '?':
|
2017-11-13 00:31:46 +00:00
|
|
|
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{"?", "substitute"})
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-13 00:31:46 +00:00
|
|
|
setter = append(setter, *tmpSetter)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return setter
|
|
|
|
}
|
|
|
|
|
2017-11-12 05:25:04 +00:00
|
|
|
func processLimit(limitstr string) (limiter DBLimit) {
|
2017-09-03 04:50:31 +00:00
|
|
|
halves := strings.Split(limitstr, ",")
|
2017-06-15 11:40:35 +00:00
|
|
|
if len(halves) == 2 {
|
|
|
|
limiter.Offset = halves[0]
|
|
|
|
limiter.MaxCount = halves[1]
|
|
|
|
} else {
|
|
|
|
limiter.MaxCount = halves[0]
|
|
|
|
}
|
|
|
|
return limiter
|
|
|
|
}
|
|
|
|
|
2017-11-10 00:16:15 +00:00
|
|
|
func isOpByte(char byte) bool {
|
2018-03-31 05:25:27 +00:00
|
|
|
return char == '<' || char == '>' || char == '=' || char == '!' || char == '*' || char == '%' || char == '+' || char == '-' || char == '/' || char == '(' || char == ')'
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-10 00:16:15 +00:00
|
|
|
func isOpRune(char rune) bool {
|
2018-03-31 05:25:27 +00:00
|
|
|
return char == '<' || char == '>' || char == '=' || char == '!' || char == '*' || char == '%' || char == '+' || char == '-' || char == '/' || char == '(' || char == ')'
|
2017-06-19 08:06:54 +00:00
|
|
|
}
|
|
|
|
|
2017-11-12 05:25:04 +00:00
|
|
|
func processFields(fieldstr string) (fields []DBField) {
|
2017-06-12 09:03:14 +00:00
|
|
|
if fieldstr == "" {
|
|
|
|
return fields
|
|
|
|
}
|
|
|
|
var buffer string
|
2017-09-03 04:50:31 +00:00
|
|
|
var lastItem int
|
2017-06-12 09:03:14 +00:00
|
|
|
fieldstr += ","
|
2017-09-03 04:50:31 +00:00
|
|
|
for i := 0; i < len(fieldstr); i++ {
|
2017-06-12 09:03:14 +00:00
|
|
|
if fieldstr[i] == '(' {
|
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
|
|
|
i = skipFunctionCall(fieldstr, i-1)
|
2017-11-12 05:25:04 +00:00
|
|
|
fields = append(fields, DBField{Name: fieldstr[lastItem : i+1], Type: getIdentifierType(fieldstr[lastItem : i+1])})
|
2017-06-12 09:03:14 +00:00
|
|
|
buffer = ""
|
2017-09-03 04:50:31 +00:00
|
|
|
lastItem = i + 2
|
2017-06-12 09:03:14 +00:00
|
|
|
} else if fieldstr[i] == ',' && buffer != "" {
|
2017-11-12 05:25:04 +00:00
|
|
|
fields = append(fields, DBField{Name: buffer, Type: getIdentifierType(buffer)})
|
2017-06-12 09:03:14 +00:00
|
|
|
buffer = ""
|
2017-09-03 04:50:31 +00:00
|
|
|
lastItem = i + 1
|
2018-04-23 08:38:25 +00:00
|
|
|
} else if (fieldstr[i] >= 32) && fieldstr[i] != ',' && fieldstr[i] != ')' {
|
2017-06-12 09:03:14 +00:00
|
|
|
buffer += string(fieldstr[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fields
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func getIdentifierType(identifier string) string {
|
2017-06-12 09:03:14 +00:00
|
|
|
if ('a' <= identifier[0] && identifier[0] <= 'z') || ('A' <= identifier[0] && identifier[0] <= 'Z') {
|
2017-09-03 04:50:31 +00:00
|
|
|
if identifier[len(identifier)-1] == ')' {
|
2017-06-12 09:03:14 +00:00
|
|
|
return "function"
|
|
|
|
}
|
|
|
|
return "column"
|
|
|
|
}
|
|
|
|
if identifier[0] == '\'' || identifier[0] == '"' {
|
|
|
|
return "string"
|
|
|
|
}
|
|
|
|
return "literal"
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func getIdentifier(segment string, startOffset int) (out string, i int) {
|
2017-06-12 09:03:14 +00:00
|
|
|
segment = strings.TrimSpace(segment)
|
|
|
|
segment += " " // Avoid overflow bugs with slicing
|
|
|
|
for i = startOffset; i < len(segment); i++ {
|
|
|
|
if segment[i] == '(' {
|
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
|
|
|
i = skipFunctionCall(segment, i)
|
2017-06-12 09:03:14 +00:00
|
|
|
return strings.TrimSpace(segment[startOffset:i]), (i - 1)
|
|
|
|
}
|
2017-11-10 00:16:15 +00:00
|
|
|
if (segment[i] == ' ' || isOpByte(segment[i])) && i != startOffset {
|
2017-06-12 09:03:14 +00:00
|
|
|
return strings.TrimSpace(segment[startOffset:i]), (i - 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(segment[startOffset:]), (i - 1)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func getOperator(segment string, startOffset int) (out string, i int) {
|
2017-06-12 09:03:14 +00:00
|
|
|
segment = strings.TrimSpace(segment)
|
|
|
|
segment += " " // Avoid overflow bugs with slicing
|
|
|
|
for i = startOffset; i < len(segment); i++ {
|
2017-11-10 00:16:15 +00:00
|
|
|
if !isOpByte(segment[i]) && i != startOffset {
|
2017-06-12 09:03:14 +00:00
|
|
|
return strings.TrimSpace(segment[startOffset:i]), (i - 1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return strings.TrimSpace(segment[startOffset:]), (i - 1)
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func skipFunctionCall(data string, index int) int {
|
2017-09-03 04:50:31 +00:00
|
|
|
var braceCount int
|
|
|
|
for ; index < len(data); index++ {
|
2017-06-12 09:03:14 +00:00
|
|
|
char := data[index]
|
|
|
|
if char == '(' {
|
2017-09-03 04:50:31 +00:00
|
|
|
braceCount++
|
2017-06-12 09:03:14 +00:00
|
|
|
} else if char == ')' {
|
2017-09-03 04:50:31 +00:00
|
|
|
braceCount--
|
|
|
|
if braceCount == 0 {
|
2017-06-12 09:03:14 +00:00
|
|
|
return index
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return index
|
|
|
|
}
|
|
|
|
|
2017-09-03 04:50:31 +00:00
|
|
|
func writeFile(name string, content string) (err error) {
|
2017-06-12 09:03:14 +00:00
|
|
|
f, err := os.Create(name)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
_, err = f.WriteString(content)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
err = f.Sync()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return f.Close()
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|