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?
|
2019-12-31 21:57:54 +00:00
|
|
|
func processColumns(colStr string) (columns []DBColumn) {
|
|
|
|
if colStr == "" {
|
2017-06-12 09:03:14 +00:00
|
|
|
return columns
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
colStr = strings.Replace(colStr, " as ", " AS ", -1)
|
|
|
|
for _, segment := range strings.Split(colStr, ",") {
|
|
|
|
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 {
|
2019-12-31 21:57:54 +00:00
|
|
|
outCol.Table = dotHalves[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
|
|
|
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 {
|
2019-12-31 21:57:54 +00:00
|
|
|
outCol.Alias = strings.TrimSpace(halves[1])
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
if halves[0][len(halves[0])-1] == ')' {
|
2019-12-31 21:57:54 +00:00
|
|
|
outCol.Type = TokenFunc
|
2017-06-19 08:06:54 +00:00
|
|
|
} else if halves[0] == "?" {
|
2019-12-31 21:57:54 +00:00
|
|
|
outCol.Type = TokenSub
|
2017-06-12 09:03:14 +00:00
|
|
|
} else {
|
2019-12-31 21:57:54 +00:00
|
|
|
outCol.Type = TokenColumn
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2017-09-03 04:50:31 +00:00
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
outCol.Left = halves[0]
|
|
|
|
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
|
2019-12-31 21:57:54 +00:00
|
|
|
func processOrderby(orderStr string) (order []DBOrder) {
|
|
|
|
if orderStr == "" {
|
2017-06-12 09:03:14 +00:00
|
|
|
return order
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
for _, segment := range strings.Split(orderStr, ",") {
|
|
|
|
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
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
outOrder.Column = halves[0]
|
|
|
|
outOrder.Order = strings.ToLower(halves[1])
|
|
|
|
order = append(order, outOrder)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return order
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func processJoiner(joinStr string) (joiner []DBJoiner) {
|
|
|
|
if joinStr == "" {
|
2017-06-12 09:03:14 +00:00
|
|
|
return joiner
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
joinStr = strings.Replace(joinStr, " on ", " ON ", -1)
|
|
|
|
joinStr = strings.Replace(joinStr, " and ", " AND ", -1)
|
|
|
|
for _, segment := range strings.Split(joinStr, " AND ") {
|
|
|
|
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)
|
2019-12-31 21:57:54 +00:00
|
|
|
outJoin.Operator, parseOffset = getOperator(segment, parseOffset+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
|
|
|
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, ".")
|
2019-12-31 21:57:54 +00:00
|
|
|
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
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
joiner = append(joiner, outJoin)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
return joiner
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (wh *DBWhere) parseNumber(segment string, i int) int {
|
2017-11-12 11:29:23 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
|
|
|
if '0' <= ch && ch <= '9' {
|
|
|
|
buffer += string(ch)
|
2017-11-12 11:29:23 +00:00
|
|
|
} else {
|
|
|
|
i--
|
2019-12-31 21:57:54 +00:00
|
|
|
wh.Expr = append(wh.Expr, DBToken{buffer, TokenNumber})
|
2017-11-12 11:29:23 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2020-01-01 01:26:15 +00:00
|
|
|
func (wh *DBWhere) parseColumn(seg string, i int) int {
|
|
|
|
//var buffer string
|
|
|
|
si := i
|
|
|
|
l := 0
|
|
|
|
for ; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
2017-11-13 00:36:31 +00:00
|
|
|
switch {
|
2019-12-31 21:57:54 +00:00
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '.' || ch == '_':
|
2020-01-01 01:26:15 +00:00
|
|
|
//buffer += string(ch)
|
|
|
|
l++
|
2019-12-31 21:57:54 +00:00
|
|
|
case ch == '(':
|
2020-01-01 01:26:15 +00:00
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
return wh.parseFunction(seg, str, i)
|
2017-11-13 00:36:31 +00:00
|
|
|
default:
|
2017-11-12 11:29:23 +00:00
|
|
|
i--
|
2020-01-01 01:26:15 +00:00
|
|
|
var str string
|
|
|
|
if l != 0 {
|
|
|
|
str = seg[si : si+l]
|
|
|
|
}
|
|
|
|
wh.Expr = append(wh.Expr, DBToken{str, TokenColumn})
|
2017-11-12 11:29:23 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2020-01-01 01:26:15 +00:00
|
|
|
func (wh *DBWhere) parseFunction(seg string, buffer string, i int) int {
|
2019-12-31 21:57:54 +00:00
|
|
|
preI := i
|
2020-01-01 01:26:15 +00:00
|
|
|
i = skipFunctionCall(seg, i-1)
|
|
|
|
buffer += seg[preI:i] + string(seg[i])
|
2019-12-31 21:57:54 +00:00
|
|
|
wh.Expr = append(wh.Expr, DBToken{buffer, TokenFunc})
|
2017-11-12 11:29:23 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (wh *DBWhere) parseString(segment string, i int) int {
|
2017-11-13 00:31:46 +00:00
|
|
|
var buffer string
|
|
|
|
i++
|
|
|
|
for ; i < len(segment); i++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
|
|
|
if ch != '\'' {
|
|
|
|
buffer += string(ch)
|
2017-11-13 00:31:46 +00:00
|
|
|
} else {
|
2019-12-31 21:57:54 +00:00
|
|
|
wh.Expr = append(wh.Expr, DBToken{buffer, TokenString})
|
2017-11-13 00:31:46 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (wh *DBWhere) parseOperator(segment string, i int) int {
|
2017-11-13 00:31:46 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
|
|
|
if isOpByte(ch) {
|
|
|
|
buffer += string(ch)
|
2017-11-13 00:31:46 +00:00
|
|
|
} else {
|
|
|
|
i--
|
2019-12-31 21:57:54 +00:00
|
|
|
wh.Expr = append(wh.Expr, DBToken{buffer, TokenOp})
|
2017-11-13 00:31:46 +00:00
|
|
|
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
|
2019-12-31 21:57:54 +00:00
|
|
|
func processWhere(whereStr string) (where []DBWhere) {
|
|
|
|
if whereStr == "" {
|
2017-06-12 09:03:14 +00:00
|
|
|
return where
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
whereStr = normalizeAnd(whereStr)
|
|
|
|
whereStr = normalizeOr(whereStr)
|
|
|
|
|
|
|
|
for _, seg := range strings.Split(whereStr, " AND ") {
|
|
|
|
tmpWhere := &DBWhere{[]DBToken{}}
|
|
|
|
seg += ")"
|
|
|
|
for i := 0; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
2019-12-31 21:57:54 +00:00
|
|
|
case '0' <= ch && ch <= '9':
|
|
|
|
i = tmpWhere.parseNumber(seg, 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
|
2019-12-31 21:57:54 +00:00
|
|
|
case ch == 'O' && (i+1) < len(seg) && seg[i+1] == 'R':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"OR", TokenOr})
|
2018-03-31 05:25:27 +00:00
|
|
|
i += 1
|
2019-12-31 21:57:54 +00:00
|
|
|
case ch == 'N' && (i+2) < len(seg) && seg[i+1] == 'O' && seg[i+2] == 'T':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"NOT", TokenNot})
|
|
|
|
i += 2
|
|
|
|
case ch == 'L' && (i+3) < len(seg) && seg[i+1] == 'I' && seg[i+2] == 'K' && seg[i+3] == 'E':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"LIKE", TokenLike})
|
|
|
|
i += 3
|
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '_':
|
|
|
|
i = tmpWhere.parseColumn(seg, i)
|
|
|
|
case ch == '\'':
|
|
|
|
i = tmpWhere.parseString(seg, i)
|
|
|
|
case ch == ')' && i < (len(seg)-1):
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{")", TokenOp})
|
|
|
|
case isOpByte(ch):
|
|
|
|
i = tmpWhere.parseOperator(seg, i)
|
|
|
|
case ch == '?':
|
|
|
|
tmpWhere.Expr = append(tmpWhere.Expr, DBToken{"?", TokenSub})
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (set *DBSetter) parseNumber(segment string, i int) int {
|
2017-11-13 00:31:46 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
|
|
|
if '0' <= ch && ch <= '9' {
|
|
|
|
buffer += string(ch)
|
2017-11-13 00:31:46 +00:00
|
|
|
} else {
|
2019-12-31 21:57:54 +00:00
|
|
|
set.Expr = append(set.Expr, DBToken{buffer, TokenNumber})
|
2017-11-13 00:31:46 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (set *DBSetter) parseColumn(segment string, i int) int {
|
2017-11-13 00:31:46 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
2019-12-31 21:57:54 +00:00
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '_':
|
|
|
|
buffer += string(ch)
|
|
|
|
case ch == '(':
|
|
|
|
return set.parseFunction(segment, buffer, i)
|
2017-11-13 05:22:37 +00:00
|
|
|
default:
|
2017-11-13 00:31:46 +00:00
|
|
|
i--
|
2019-12-31 21:57:54 +00:00
|
|
|
set.Expr = append(set.Expr, DBToken{buffer, TokenColumn})
|
2017-11-13 00:31:46 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (set *DBSetter) parseFunction(segment string, buffer string, i int) int {
|
|
|
|
preI := i
|
2017-11-13 00:31:46 +00:00
|
|
|
i = skipFunctionCall(segment, i-1)
|
|
|
|
buffer += segment[preI:i] + string(segment[i])
|
2019-12-31 21:57:54 +00:00
|
|
|
set.Expr = append(set.Expr, DBToken{buffer, TokenFunc})
|
2017-11-13 00:31:46 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (set *DBSetter) parseString(segment string, i int) int {
|
2017-11-13 00:31:46 +00:00
|
|
|
var buffer string
|
|
|
|
i++
|
|
|
|
for ; i < len(segment); i++ {
|
|
|
|
char := segment[i]
|
|
|
|
if char != '\'' {
|
|
|
|
buffer += string(char)
|
|
|
|
} else {
|
2019-12-31 21:57:54 +00:00
|
|
|
set.Expr = append(set.Expr, DBToken{buffer, TokenString})
|
2017-11-13 00:31:46 +00:00
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func (set *DBSetter) parseOperator(segment string, i int) int {
|
2017-11-13 00:31:46 +00:00
|
|
|
var buffer string
|
|
|
|
for ; i < len(segment); i++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
|
|
|
if isOpByte(ch) {
|
|
|
|
buffer += string(ch)
|
2017-11-13 00:31:46 +00:00
|
|
|
} else {
|
|
|
|
i--
|
2019-12-31 21:57:54 +00:00
|
|
|
set.Expr = append(set.Expr, DBToken{buffer, TokenOp})
|
2017-11-13 00:31:46 +00:00
|
|
|
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++ {
|
2019-12-31 21:57:54 +00:00
|
|
|
ch := segment[i]
|
2017-11-13 05:22:37 +00:00
|
|
|
switch {
|
2019-12-31 21:57:54 +00:00
|
|
|
case '0' <= ch && ch <= '9':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseNumber(segment, i)
|
2019-12-31 21:57:54 +00:00
|
|
|
case ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ch == '_':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseColumn(segment, i)
|
2019-12-31 21:57:54 +00:00
|
|
|
case ch == '\'':
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseString(segment, i)
|
2019-12-31 21:57:54 +00:00
|
|
|
case isOpByte(ch):
|
2017-11-13 00:31:46 +00:00
|
|
|
i = tmpSetter.parseOperator(segment, i)
|
2019-12-31 21:57:54 +00:00
|
|
|
case ch == '?':
|
|
|
|
tmpSetter.Expr = append(tmpSetter.Expr, DBToken{"?", TokenSub})
|
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
|
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func processLimit(limitStr string) (limit DBLimit) {
|
|
|
|
halves := strings.Split(limitStr, ",")
|
2017-06-15 11:40:35 +00:00
|
|
|
if len(halves) == 2 {
|
2019-12-31 21:57:54 +00:00
|
|
|
limit.Offset = halves[0]
|
|
|
|
limit.MaxCount = halves[1]
|
2017-06-15 11:40:35 +00:00
|
|
|
} else {
|
2019-12-31 21:57:54 +00:00
|
|
|
limit.MaxCount = halves[0]
|
2017-06-15 11:40:35 +00:00
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
return limit
|
2017-06-15 11:40:35 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func isOpByte(ch byte) bool {
|
|
|
|
return ch == '<' || ch == '>' || ch == '=' || ch == '!' || ch == '*' || ch == '%' || ch == '+' || ch == '-' || ch == '/' || ch == '(' || ch == ')'
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func isOpRune(ch rune) bool {
|
|
|
|
return ch == '<' || ch == '>' || ch == '=' || ch == '!' || ch == '*' || ch == '%' || ch == '+' || ch == '-' || ch == '/' || ch == '(' || ch == ')'
|
2017-06-19 08:06:54 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func processFields(fieldStr string) (fields []DBField) {
|
|
|
|
if fieldStr == "" {
|
2017-06-12 09:03:14 +00:00
|
|
|
return fields
|
|
|
|
}
|
|
|
|
var buffer string
|
2017-09-03 04:50:31 +00:00
|
|
|
var lastItem int
|
2019-12-31 21:57:54 +00:00
|
|
|
fieldStr += ","
|
|
|
|
for i := 0; i < len(fieldStr); i++ {
|
|
|
|
ch := fieldStr[i]
|
|
|
|
if ch == '(' {
|
|
|
|
i = skipFunctionCall(fieldStr, i-1)
|
|
|
|
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
|
2019-12-31 21:57:54 +00:00
|
|
|
} else if ch == ',' && 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
|
2019-12-31 21:57:54 +00:00
|
|
|
} else if (ch >= 32) && ch != ',' && ch != ')' {
|
|
|
|
buffer += string(ch)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return fields
|
|
|
|
}
|
|
|
|
|
2020-01-01 01:26:15 +00:00
|
|
|
func getIdentifierType(iden string) int {
|
2019-12-31 21:57:54 +00:00
|
|
|
if ('a' <= iden[0] && iden[0] <= 'z') || ('A' <= iden[0] && iden[0] <= 'Z') {
|
|
|
|
if iden[len(iden)-1] == ')' {
|
2020-01-01 01:26:15 +00:00
|
|
|
return IdenFunc
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2020-01-01 01:26:15 +00:00
|
|
|
return IdenColumn
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
if iden[0] == '\'' || iden[0] == '"' {
|
2020-01-01 01:26:15 +00:00
|
|
|
return IdenString
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2020-01-01 01:26:15 +00:00
|
|
|
return IdenLiteral
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func getIdentifier(seg string, startOffset int) (out string, i int) {
|
|
|
|
seg = strings.TrimSpace(seg)
|
|
|
|
seg += " " // Avoid overflow bugs with slicing
|
|
|
|
for i = startOffset; i < len(seg); i++ {
|
|
|
|
ch := seg[i]
|
|
|
|
if ch == '(' {
|
|
|
|
i = skipFunctionCall(seg, i)
|
|
|
|
return strings.TrimSpace(seg[startOffset:i]), (i - 1)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
if (ch == ' ' || isOpByte(ch)) && i != startOffset {
|
|
|
|
return strings.TrimSpace(seg[startOffset:i]), (i - 1)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
return strings.TrimSpace(seg[startOffset:]), (i - 1)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-31 21:57:54 +00:00
|
|
|
func getOperator(seg string, startOffset int) (out string, i int) {
|
|
|
|
seg = strings.TrimSpace(seg)
|
|
|
|
seg += " " // Avoid overflow bugs with slicing
|
|
|
|
for i = startOffset; i < len(seg); i++ {
|
|
|
|
if !isOpByte(seg[i]) && i != startOffset {
|
|
|
|
return strings.TrimSpace(seg[startOffset:i]), (i - 1)
|
2017-06-12 09:03:14 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-31 21:57:54 +00:00
|
|
|
return strings.TrimSpace(seg[startOffset:]), (i - 1)
|
2017-06-12 09:03:14 +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
|
|
|
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
|
|
|
}
|