I am writing a program in Go that allows users to put a query to a 
database. This program uses multiple different drivers such as Postgres, 
MySQL, and I want to be able to add other drivers as needed. This is 
supposed to be something a user can use and depending on how the 
configuration file is setup, connect to the server using the driver for 
that server, as well as the configured username / password. I've integrated 
it in to use my company's authentication system so that it can checks the 
user's rights on the server to make sure that user has the authority to run 
the commands specified. So a user can type ANY query they want -- select 
update insert etc....

sqlrun -h mysqlsrv -e "select..."

 sqlrun -h postgressrv -e "update ..."

-h Specifies the host and in a config file the host is configured with the 
driver, default database, username, and an encrypted password, I've 
integrated it in to my company's authentication system to know if the user 
can execute queries at all, or read only, or can write to the database. 

So right now I pass all user given queries to sql.Query(). This works but 
when the user is doing an update or insert -- I can't output the number of 
rows impacted, for that I would need to use sql.Exec()

What I want to know is if there is a way to get Rows impacted with a query, 
or if there is a more comprehensive way to evaluate the query to know if I 
should query or exec? I've looked into doing simple things like look at the 
first word, if it's select, run query, if it's update or insert run exec. 
The problem with that is the complexity of sql, you can have a select 
statement that doesn't start with the word select... For example: "WITH 
temporary_name AS (SELECT * FROM table_name)..."  I am sure there could be 
others where Insert or Update are not always the first word of the query... 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/530c3310-c997-4620-abe1-9e6f570d8666n%40googlegroups.com.

Reply via email to