Skip to content

Commit

Permalink
Merge pull request cockroachdb#84374 from dhartunian/backport22.1-79663
Browse files Browse the repository at this point in the history
  • Loading branch information
dhartunian authored Aug 5, 2022
2 parents 64466ef + 1d0c735 commit 033c911
Show file tree
Hide file tree
Showing 8 changed files with 1,104 additions and 0 deletions.
187 changes: 187 additions & 0 deletions docs/generated/swagger/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,193 @@
}
}
},
"/sql/": {
"post": {
"description": "Executes one or more SQL statements.\n\nIf the execute parameter is not specified, only check the SQL\nsyntax.\n\nIf only one SQL statement is specified, it is executed using an\nimplicit transaction.\n\nIf multiple SQL statements are specified and the multi_statement\noption is set, the SQL statements are executed using a common\ntransaction. This means that the client cannot use\nBEGIN/COMMIT/ROLLBACK. If any statement encounters a non-retriable\nerror, the transaction is aborted and execution stops.\n\nOnly a single SQL statement is allowed if the multi_statement\noption is not set, as a form of protection against SQL injection\nattacks.\n\nThere is no session state shared across the statements. For example,\nSET statements are ineffective.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"summary": "Execute one or more SQL statements",
"operationId": "execSQL",
"parameters": [
{
"name": "request",
"in": "body",
"schema": {
"type": "object",
"required": [
"statements"
],
"properties": {
"application_name": {
"description": "The SQL application_name parameter.",
"type": "string"
},
"database": {
"description": "The current database for the execution. Defaults to defaultdb.",
"type": "string"
},
"max_result_size": {
"description": "Max size in bytes for the execution field in the response. Execution stops with an error if the results do not fit.",
"type": "integer"
},
"statements": {
"description": "The SQL statement(s) to run.",
"type": "array",
"items": {
"type": "object",
"required": [
"sql"
],
"properties": {
"arguments": {
"description": "Placeholder parameter values.",
"type": "array"
},
"sql": {
"description": "SQL syntax for one statement.",
"type": "string"
}
}
}
},
"timeout": {
"description": "Max time budget for the execution, using Go duration syntax. Default to 5 seconds.",
"type": "string"
}
}
}
}
],
"responses": {
"200": {
"description": "Query results and optional execution error.",
"schema": {
"type": "object",
"required": [
"num_statements",
"execution"
],
"properties": {
"execution": {
"type": "object",
"required": [
"retries",
"txn_results"
],
"properties": {
"retries": {
"description": "The number of times the transaction was retried.",
"type": "integer"
},
"txn_results": {
"description": "The result sets, one per SQL statement.",
"type": "array",
"items": {
"type": "object",
"required": [
"statement",
"tag",
"start",
"end"
],
"properties": {
"columns": {
"description": "The list of columns in the result rows.",
"type": "array",
"items": {
"type": "object",
"required": [
"name",
"type",
"oid"
],
"properties": {
"name": {
"description": "The column name.",
"type": "string"
},
"oid": {
"description": "The PostgreSQL OID for the column type.",
"type": "integer"
},
"type": {
"description": "The SQL type of the column.",
"type": "string"
}
}
}
},
"end": {
"description": "End timestamp, encoded as RFC3339.",
"type": "string"
},
"rows": {
"description": "The result rows.",
"type": "array",
"items": {}
},
"rows_affected": {
"description": "The number of rows affected.",
"type": "integer"
},
"start": {
"description": "Start timestamp, encoded as RFC3339.",
"type": "string"
},
"statement": {
"description": "The statement index in the SQL input.",
"type": "integer"
},
"tag": {
"description": "The short statement tag.",
"type": "string"
}
}
}
}
}
},
"num_statements": {
"description": "The number of statements in the input SQL.",
"type": "integer"
},
"txn_error": {
"description": "The details of the error, if an error was encountered.",
"type": "object",
"required": [
"message",
"code"
],
"properties": {
"code": {
"description": "The SQLSTATE 5-character code of the error.",
"type": "string"
},
"message": {
"type": "string"
}
},
"additionalProperties": false
}
}
}
},
"400": {
"description": "Bad request. Bad input encoding, missing SQL or invalid parameter."
},
"405": {
"description": "Bad method. Only the POST method is supported."
},
"500": {
"description": "Internal error encountered."
}
}
}
},
"/users/": {
"get": {
"description": "List SQL users on this cluster.",
Expand Down
4 changes: 4 additions & 0 deletions pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ go_library(
"api_v2_auth.go",
"api_v2_error.go",
"api_v2_ranges.go",
"api_v2_sql.go",
"api_v2_sql_schema.go",
"authentication.go",
"auto_tls_init.go",
Expand Down Expand Up @@ -170,6 +171,7 @@ go_library(
"//pkg/sql/optionalnodeliveness",
"//pkg/sql/parser",
"//pkg/sql/pgwire",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/pgwire/pgwirecancel",
"//pkg/sql/physicalplan",
"//pkg/sql/querycache",
Expand Down Expand Up @@ -215,6 +217,7 @@ go_library(
"//pkg/util/httputil",
"//pkg/util/humanizeutil",
"//pkg/util/iterutil",
"//pkg/util/json",
"//pkg/util/log",
"//pkg/util/log/eventpb",
"//pkg/util/log/logcrash",
Expand Down Expand Up @@ -312,6 +315,7 @@ go_test(
"admin_test.go",
"api_v2_ranges_test.go",
"api_v2_sql_schema_test.go",
"api_v2_sql_test.go",
"api_v2_test.go",
"authentication_test.go",
"auto_tls_init_test.go",
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/api_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ func (a *apiV2Server) registerRoutes(innerMux *mux.Router, authMux http.Handler)
{"databases/{database_name:[\\w.]+}/tables/", a.databaseTables, true, regularRole, noOption},
{"databases/{database_name:[\\w.]+}/tables/{table_name:[\\w.]+}/", a.tableDetails, true, regularRole, noOption},
{"rules/", a.listRules, false, regularRole, noOption},

{"sql/", a.execSQL, true, regularRole, noOption},
}

// For all routes requiring authentication, have the outer mux (a.mux)
Expand Down
Loading

0 comments on commit 033c911

Please sign in to comment.