Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

database/sql: discrepancy with Wiki in examples #28208

Closed
albertorestifo opened this issue Oct 15, 2018 · 5 comments
Closed

database/sql: discrepancy with Wiki in examples #28208

albertorestifo opened this issue Oct 15, 2018 · 5 comments

Comments

@albertorestifo
Copy link

@albertorestifo albertorestifo commented Oct 15, 2018

There is a minor usage discrepancy between the SQLInterface wiki page and the documentation of the database/sql package when illustrating variables replacement:

From the wiki:

db.Query("SELECT name FROM users WHERE age = $1", age)

From the examples in the database/sql/example_test.go:21 (other examples affected too):

db.QueryContext(ctx, "SELECT name FROM users WHERE age=?", age)

I think all examples should use the same pattern as the wiki to avoid confusion

@agnivade
Copy link
Contributor

@agnivade agnivade commented Oct 15, 2018

I wouldn't label it as a discrepancy. I think it's good to have different sorts of examples so that people know that both $ and ? are valid syntax. Maybe we can document somewhere the difference between $ and ?. Not sure if it is already covered somewhere.

@kardianos

@FiloSottile FiloSottile changed the title database/sql Discrepancy with Wiki in examples database/sql: discrepancy with Wiki in examples Oct 15, 2018
@FiloSottile FiloSottile added this to the Unplanned milestone Oct 15, 2018
@kardianos
Copy link
Contributor

@kardianos kardianos commented Oct 17, 2018

@agnivade The $ vs ? is DB specific. Other systems use @name rather then ?NN or $NN. Some can accept both. I'm sure we could put a comment about identifiers in the wiki, and include named identifiers, ?, and $ styles, and point to specific documentation for several instances.

  • SQL Server
  • Postgresql
  • MySQL
  • Oracle

We can also adjust the usage of Query to QueryContext too.

Easy issue. Anyone can help with this one.

@yo-tak
Copy link
Contributor

@yo-tak yo-tak commented Oct 18, 2018

@kardianos Hi, I'd love to give it a try for this one!
Before actually creating a pull request, I want to confirm one thing, what do you mean by "adjust the usage of Query to QueryContext"? My understanding is, you mean "Query" should be replaced by "QueryContext", am I correct?

@kardianos
Copy link
Contributor

@kardianos kardianos commented Oct 18, 2018

Yes, correct.

@kardianos kardianos closed this Oct 27, 2018
@kardianos
Copy link
Contributor

@kardianos kardianos commented Oct 27, 2018

I've updated the wiki examples.

@golang golang locked and limited conversation to collaborators Oct 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants
You can’t perform that action at this time.