@@ -49,13 +49,12 @@ func (p *planner) DeclareCursor(ctx context.Context, s *tree.DeclareCursor) (pla
4949 }
5050
5151 ie := p .ExecCfg ().InternalExecutorFactory .NewInternalExecutor (p .SessionData ())
52- cursorName := s .Name .String ()
53- if cursor := p .sqlCursors .getCursor (cursorName ); cursor != nil {
54- return nil , pgerror .Newf (pgcode .DuplicateCursor , "cursor %q already exists" , cursorName )
52+ if cursor := p .sqlCursors .getCursor (s .Name ); cursor != nil {
53+ return nil , pgerror .Newf (pgcode .DuplicateCursor , "cursor %q already exists" , s .Name )
5554 }
5655
57- if p .extendedEvalCtx .PreparedStatementState .HasPortal (cursorName ) {
58- return nil , pgerror .Newf (pgcode .DuplicateCursor , "cursor %q already exists as portal" , cursorName )
56+ if p .extendedEvalCtx .PreparedStatementState .HasPortal (string ( s . Name ) ) {
57+ return nil , pgerror .Newf (pgcode .DuplicateCursor , "cursor %q already exists as portal" , s . Name )
5958 }
6059
6160 // Try to plan the cursor query to make sure that it's valid.
@@ -100,7 +99,7 @@ func (p *planner) DeclareCursor(ctx context.Context, s *tree.DeclareCursor) (pla
10099 statement : statement ,
101100 created : timeutil .Now (),
102101 }
103- if err := p .sqlCursors .addCursor (cursorName , cursor ); err != nil {
102+ if err := p .sqlCursors .addCursor (s . Name , cursor ); err != nil {
104103 // This case shouldn't happen because cursor names are scoped to a session,
105104 // and sessions can't have more than one statement running at once. But
106105 // let's be diligent and clean up if it somehow does happen anyway.
@@ -119,11 +118,10 @@ var errBackwardScan = pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "cursor
119118func (p * planner ) FetchCursor (
120119 _ context.Context , s * tree.CursorStmt , isMove bool ,
121120) (planNode , error ) {
122- cursorName := s .Name .String ()
123- cursor := p .sqlCursors .getCursor (cursorName )
121+ cursor := p .sqlCursors .getCursor (s .Name )
124122 if cursor == nil {
125123 return nil , pgerror .Newf (
126- pgcode .InvalidCursorName , "cursor %q does not exist" , cursorName ,
124+ pgcode .InvalidCursorName , "cursor %q does not exist" , s . Name ,
127125 )
128126 }
129127 if s .Count < 0 || s .FetchType == tree .FetchBackwardAll {
@@ -243,7 +241,7 @@ func (p *planner) CloseCursor(ctx context.Context, n *tree.CloseCursor) (planNod
243241 return & delayedNode {
244242 name : n .String (),
245243 constructor : func (ctx context.Context , p * planner ) (planNode , error ) {
246- return newZeroNode (nil /* columns */ ), p .sqlCursors .closeCursor (n .Name . String () )
244+ return newZeroNode (nil /* columns */ ), p .sqlCursors .closeCursor (n .Name )
247245 },
248246 }, nil
249247}
@@ -276,20 +274,20 @@ type sqlCursors interface {
276274 closeAll ()
277275 // closeCursor closes the named cursor, returning an error if that cursor
278276 // didn't exist in the set.
279- closeCursor (string ) error
277+ closeCursor (tree. Name ) error
280278 // getCursor returns the named cursor, returning nil if that cursor
281279 // didn't exist in the set.
282- getCursor (string ) * sqlCursor
280+ getCursor (tree. Name ) * sqlCursor
283281 // addCursor adds a new cursor with the given name to the set, returning an
284282 // error if the cursor already existed in the set.
285- addCursor (string , * sqlCursor ) error
283+ addCursor (tree. Name , * sqlCursor ) error
286284 // list returns all open cursors in the set.
287- list () map [string ]* sqlCursor
285+ list () map [tree. Name ]* sqlCursor
288286}
289287
290288// cursorMap is a sqlCursors that's backed by an actual map.
291289type cursorMap struct {
292- cursors map [string ]* sqlCursor
290+ cursors map [tree. Name ]* sqlCursor
293291}
294292
295293func (c * cursorMap ) closeAll () {
@@ -299,7 +297,7 @@ func (c *cursorMap) closeAll() {
299297 c .cursors = nil
300298}
301299
302- func (c * cursorMap ) closeCursor (s string ) error {
300+ func (c * cursorMap ) closeCursor (s tree. Name ) error {
303301 cursor , ok := c .cursors [s ]
304302 if ! ok {
305303 return pgerror .Newf (pgcode .InvalidCursorName , "cursor %q does not exist" , s )
@@ -309,13 +307,13 @@ func (c *cursorMap) closeCursor(s string) error {
309307 return err
310308}
311309
312- func (c * cursorMap ) getCursor (s string ) * sqlCursor {
310+ func (c * cursorMap ) getCursor (s tree. Name ) * sqlCursor {
313311 return c .cursors [s ]
314312}
315313
316- func (c * cursorMap ) addCursor (s string , cursor * sqlCursor ) error {
314+ func (c * cursorMap ) addCursor (s tree. Name , cursor * sqlCursor ) error {
317315 if c .cursors == nil {
318- c .cursors = make (map [string ]* sqlCursor )
316+ c .cursors = make (map [tree. Name ]* sqlCursor )
319317 }
320318 if _ , ok := c .cursors [s ]; ok {
321319 return pgerror .Newf (pgcode .DuplicateCursor , "cursor %q already exists" , s )
@@ -324,7 +322,7 @@ func (c *cursorMap) addCursor(s string, cursor *sqlCursor) error {
324322 return nil
325323}
326324
327- func (c * cursorMap ) list () map [string ]* sqlCursor {
325+ func (c * cursorMap ) list () map [tree. Name ]* sqlCursor {
328326 return c .cursors
329327}
330328
@@ -338,19 +336,19 @@ func (c connExCursorAccessor) closeAll() {
338336 c .ex .extraTxnState .sqlCursors .closeAll ()
339337}
340338
341- func (c connExCursorAccessor ) closeCursor (s string ) error {
339+ func (c connExCursorAccessor ) closeCursor (s tree. Name ) error {
342340 return c .ex .extraTxnState .sqlCursors .closeCursor (s )
343341}
344342
345- func (c connExCursorAccessor ) getCursor (s string ) * sqlCursor {
343+ func (c connExCursorAccessor ) getCursor (s tree. Name ) * sqlCursor {
346344 return c .ex .extraTxnState .sqlCursors .getCursor (s )
347345}
348346
349- func (c connExCursorAccessor ) addCursor (s string , cursor * sqlCursor ) error {
347+ func (c connExCursorAccessor ) addCursor (s tree. Name , cursor * sqlCursor ) error {
350348 return c .ex .extraTxnState .sqlCursors .addCursor (s , cursor )
351349}
352350
353- func (c connExCursorAccessor ) list () map [string ]* sqlCursor {
351+ func (c connExCursorAccessor ) list () map [tree. Name ]* sqlCursor {
354352 return c .ex .extraTxnState .sqlCursors .list ()
355353}
356354
0 commit comments