@@ -27,7 +27,7 @@ import (
2727 "github.com/dolthub/go-mysql-server/sql/types"
2828)
2929
30- func newCreateView (db memory.MemoryDatabase , isReplace bool ) * plan.CreateView {
30+ func newCreateView (db memory.MemoryDatabase , ifNotExists , isReplace bool ) * plan.CreateView {
3131 table := memory .NewTable (db .Database (), "mytable" , sql .NewPrimaryKeySchema (sql.Schema {
3232 {Name : "i" , Source : "mytable" , Type : types .Int32 },
3333 {Name : "s" , Source : "mytable" , Type : types .Text },
@@ -44,7 +44,7 @@ func newCreateView(db memory.MemoryDatabase, isReplace bool) *plan.CreateView {
4444 ),
4545 )
4646
47- createView := plan .NewCreateView (db , subqueryAlias .Name (), subqueryAlias , isReplace , "CREATE VIEW myview AS SELECT i FROM mytable" , "" , "" , "" )
47+ createView := plan .NewCreateView (db , subqueryAlias .Name (), subqueryAlias , ifNotExists , isReplace , "CREATE VIEW myview AS SELECT i FROM mytable" , "" , "" , "" )
4848
4949 return createView
5050}
@@ -54,7 +54,7 @@ func newCreateView(db memory.MemoryDatabase, isReplace bool) *plan.CreateView {
5454func TestCreateViewWithRegistry (t * testing.T ) {
5555 require := require .New (t )
5656
57- createView := newCreateView (memory .NewViewlessDatabase ("mydb" ), false )
57+ createView := newCreateView (memory .NewViewlessDatabase ("mydb" ), false , false )
5858
5959 ctx := sql .NewContext (context .Background ())
6060 _ , err := DefaultBuilder .buildNodeExec (ctx , createView , nil )
@@ -68,7 +68,8 @@ func TestCreateViewWithRegistry(t *testing.T) {
6868
6969// Tests that CreateView RowIter returns an error when the view exists
7070func TestCreateExistingViewNative (t * testing.T ) {
71- createView := newCreateView (memory .NewDatabase ("mydb" ), false )
71+ createView := newCreateView (memory .NewDatabase ("mydb" ), false , false )
72+ createExistingView := newCreateView (memory .NewDatabase ("mydb" ), true , false )
7273
7374 ctx := sql .NewContext (context .Background ())
7475 _ , err := DefaultBuilder .buildNodeExec (ctx , createView , nil )
@@ -78,13 +79,17 @@ func TestCreateExistingViewNative(t *testing.T) {
7879 _ , err = DefaultBuilder .buildNodeExec (ctx , createView , nil )
7980 require .Error (t , err )
8081 require .True (t , sql .ErrExistingView .Is (err ))
82+
83+ ctx = sql .NewContext (context .Background ())
84+ _ , err = DefaultBuilder .buildNodeExec (ctx , createExistingView , nil )
85+ require .NoError (t , err )
8186}
8287
8388// Tests that CreateView RowIter succeeds when the view exists and the
8489// IsReplace flag is set to true
8590func TestReplaceExistingViewNative (t * testing.T ) {
8691 db := memory .NewDatabase ("mydb" )
87- createView := newCreateView (db , false )
92+ createView := newCreateView (db , false , false )
8893
8994 ctx := sql .NewContext (context .Background ())
9095 _ , err := DefaultBuilder .buildNodeExec (ctx , createView , nil )
@@ -110,7 +115,7 @@ func TestReplaceExistingViewNative(t *testing.T) {
110115 ),
111116 )
112117
113- createView = plan .NewCreateView (db , subqueryAlias .Name (), subqueryAlias , true , "CREATE VIEW myview AS SELECT i + 1 FROM mytable" , "" , "" , "" )
118+ createView = plan .NewCreateView (db , subqueryAlias .Name (), subqueryAlias , false , true , "CREATE VIEW myview AS SELECT i + 1 FROM mytable" , "" , "" , "" )
114119 _ , err = DefaultBuilder .buildNodeExec (ctx , createView , nil )
115120 require .NoError (t , err )
116121
@@ -124,7 +129,7 @@ func TestReplaceExistingViewNative(t *testing.T) {
124129// the catalog when RowIter is called
125130func TestCreateViewNative (t * testing.T ) {
126131 db := memory .NewDatabase ("mydb" )
127- createView := newCreateView (db , false )
132+ createView := newCreateView (db , false , false )
128133
129134 ctx := sql .NewContext (context .Background ())
130135 _ , err := DefaultBuilder .buildNodeExec (ctx , createView , nil )
@@ -141,7 +146,7 @@ func TestCreateViewNative(t *testing.T) {
141146func TestCreateExistingViewWithRegistry (t * testing.T ) {
142147 require := require .New (t )
143148
144- createView := newCreateView (memory .NewViewlessDatabase ("mydb" ), false )
149+ createView := newCreateView (memory .NewViewlessDatabase ("mydb" ), false , false )
145150
146151 view := createView .View ()
147152 viewReg := sql .NewViewRegistry ()
@@ -161,7 +166,7 @@ func TestCreateExistingViewWithRegistry(t *testing.T) {
161166func TestReplaceExistingViewWithRegistry (t * testing.T ) {
162167 require := require .New (t )
163168
164- createView := newCreateView (memory .NewViewlessDatabase ("mydb" ), false )
169+ createView := newCreateView (memory .NewViewlessDatabase ("mydb" ), false , false )
165170
166171 view := sql .NewView (createView .Name , nil , "" , "" )
167172 viewReg := sql .NewViewRegistry ()
0 commit comments