This is what I expected to see and it is dissapointing to see it is not how 
it is implemented even 3 years after your post.



On Tuesday, June 11, 2013 at 7:29:45 PM UTC-5, John Nagle wrote:
>
>    There's a standardized set of SQLSTATE codes for SQL 
> systems.  Postgres and IBM DB2 use them directly. 
> That's what the Go SQL interface should be returning 
> on an error. MySQL has different codes, but there's a translation 
> table at 
>
>
> http://dev.mysql.com/doc/refman/5.7/en/connector-j-reference-error-sqlstates.html
>  
>
>      SQLite also has its own set of codes, and those too 
> should be translated. 
>
>      The "error" type returned by SQL packages should have 
> a Sqlstate() function to return the system-independent error 
> code, and perhaps a function to return the system-dependent 
> error code.  Losing that information is unacceptable for 
> any serious database work. 
>
>                                 John Nagle 
>
> On 6/11/2013 12:07 AM, Julien Schmidt wrote: 
> > Giving this another thought, this would be an race condition. 
> > But the chance might be very low that someone other registers another 
> > account with this id in the meantime. I think I would risk to let the 
> > registration fail in such a case. 
> > 
> > On Tuesday, June 11, 2013 9:01:58 AM UTC+2, Julien Schmidt wrote: 
> >> 
> >> In such a case I would make another query to check for an existing 
> account 
> >> with that id before even trying to insert the new account data. 
> >> 
> >> Something like this should work: 
> >> 
> >> var duplicate bool 
> >> err := db.QueryRow("SELECT 1 FROM users WHERE id = ? LIMIT 1", 
> >> id).Scan(&duplicate) 
> >> 
> >> On Sunday, June 9, 2013 9:34:20 AM UTC+2, Jochen Voss wrote: 
> >>> 
> >>> Dear Andy, 
> >>> 
> >>> Many thanks for your answer. 
> >>> 
> >>> On Sunday, 9 June 2013 01:17:06 UTC+2, Andy Balholm wrote: 
> >>>> 
> >>>> The errors are specific to the database backend. At least some 
> backends 
> >>>> define their own error type; for example 
> >>>> http://godoc.org/github.com/lib/pq#PGError . So use a type assertion 
> or 
> >>>> type switch on the error; if it is the backend's database error type, 
> check 
> >>>> to see if it is the specific kind of error that you're looking for. 
> >>> 
> >>> 
> >>> This sounds painful!  Are libraries using sql databases then forced to 
> be 
> >>> backend specific (if they do error handling)? 
> >>> 
> >>> What I'm trying to do is to implement an account system, which stores 
> >>> user information in a database.  When somebody tries to add a new 
> account, 
> >>> I need to tell apart duplicate user names from other problems (like 
> the DB 
> >>> server being down, the table not existing, etc.)  It would be great if 
> >>> there was a backend-independent way of doing this. 
> >>> 
> >>> Many thanks, 
> >>> Jochen 
> >>> 
> >>> 
> > 
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to