GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — vitess-sqlparser/sqlparser/sqlparser_test.go at develop · blastrain/vitess-sqlparser

Expand file tree

/

sqlparser_test.go

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
71 lines (63 loc) · 1.78 KB
/

sqlparser_test.go

Copy path

File metadata and controls

71 lines (63 loc) · 1.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package sqlparser
import (
"reflect"
"testing"
)
func checkErr(t *testing.T, err error) {
if err != nil {
t.Fatalf("%+v", err)
}
}
func checkEqual(t *testing.T, src interface{}, dst interface{}) {
if !reflect.DeepEqual(src, dst) {
t.Fatalf("not equal %v and %v", src, dst)
}
}
func TestDropTableParsing(t *testing.T) {
_, err := Parse(`DROP table if exists users`)
checkErr(t, err)
}
func TestSelectParsing(t *testing.T) {
_, err := Parse(`SELECT * from users where id = 1 order by created_at limit 1 offset 3`)
checkErr(t, err)
}
func TestCreateTableParsing(t *testing.T) {
_, err := Parse(`
CREATE TABLE users (
id bigint(20) unsigned NOT NULL,
other_id bigint(20) unsigned NOT NULL,
enum_column enum('a','b','c','d') DEFAULT NULL,
int_column int(10) DEFAULT '0',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`)
checkErr(t, err)
}
func TestCreateTableWithPartition(t *testing.T) {
_, err := Parse(`
CREATE TABLE histories (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
user_id bigint(20) unsigned NOT NULL,
note text NOT NULL,
created_at datetime NOT NULL,
updated_at datetime NOT NULL,
PRIMARY KEY (id,created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
/*!50500 PARTITION BY RANGE COLUMNS(created_at)
(PARTITION p201812 VALUES LESS THAN ('2019-01-01') ENGINE = InnoDB,
PARTITION p201901 VALUES LESS THAN ('2019-02-01') ENGINE = InnoDB,
PARTITION p201902 VALUES LESS THAN ('2019-03-01') ENGINE = InnoDB,
PARTITION p201903 VALUES LESS THAN ('2019-04-01') ENGINE = InnoDB) */;
`)
checkErr(t, err)
}
func TestShowCreateTableParsing(t *testing.T) {
ast, err := Parse(`SHOW CREATE TABLE users`)
checkErr(t, err)
switch stmt := ast.(type) {
case *Show:
checkEqual(t, "users", stmt.TableName)
default:
t.Fatalf("%+v", "type mismatch")
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.