Class SpannerCommandTextBuilder
Builds the CommandText string for executing a query or operation on a Spanner database. Instances are constructed with static factory methods.
Namespace: Google.Cloud.Spanner.Data
Assembly: Google.Cloud.Spanner.Data.dll
Syntax
public sealed class SpannerCommandTextBuilder
Properties
CommandText
Gets the resulting string to be used for CommandText.
Declaration
public string CommandText { get; }
Property Value
Type | Description |
---|---|
string |
ExtraStatements
A set of additional statements to execute if supported by the command.
Declaration
public IReadOnlyList<string> ExtraStatements { get; }
Property Value
Type | Description |
---|---|
IReadOnlyList<string> |
ProtobufDescriptors
The set of protobuf descriptors that can be used to create proto bundles. May be null.
Declaration
public FileDescriptorSet ProtobufDescriptors { get; }
Property Value
Type | Description |
---|---|
FileDescriptorSet |
ReadOptions
The read options for this command if the command is Read, or null otherwise.
Declaration
public ReadOptions ReadOptions { get; }
Property Value
Type | Description |
---|---|
ReadOptions |
SpannerCommandType
Gets the type of Spanner command (Select, Read, Update, Delete, InsertOrUpdate, Insert, Ddl, Dml).
Declaration
public SpannerCommandType SpannerCommandType { get; }
Property Value
Type | Description |
---|---|
SpannerCommandType |
TargetTable
Returns the target Spanner database table if the command is Read, Update, Delete, InsertOrUpdate, or Insert, or null otherwise.
Declaration
public string TargetTable { get; }
Property Value
Type | Description |
---|---|
string |
Methods
CreateDdlTextBuilder(string, FileDescriptorSet, params string[])
Creates a SpannerCommandTextBuilder instance that generates CommandText for executing a DDL statement.
Declaration
public static SpannerCommandTextBuilder CreateDdlTextBuilder(string ddlStatement, FileDescriptorSet protobufDescriptors, params string[] extraDdlStatements)
Parameters
Type | Name | Description |
---|---|---|
string | ddlStatement | The full DDL statement. Must not be null. |
FileDescriptorSet | protobufDescriptors | The set of protobuf descriptors that can be used to create proto bundles. May be null. |
string[] | extraDdlStatements | An optional set of additional DDL statements to execute after the first statement. Extra Ddl statements cannot be used to create additional databases. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Ddl Spanner command. |
CreateDdlTextBuilder(string, params string[])
Creates a SpannerCommandTextBuilder instance that generates CommandText for executing a DDL statement.
Declaration
public static SpannerCommandTextBuilder CreateDdlTextBuilder(string ddlStatement, params string[] extraDdlStatements)
Parameters
Type | Name | Description |
---|---|---|
string | ddlStatement | The full DDL statement. Must not be null. |
string[] | extraDdlStatements | An optional set of additional DDL statements to execute after the first statement. Extra Ddl statements cannot be used to create additional databases. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Ddl Spanner command. |
CreateDeleteTextBuilder(string)
Creates a SpannerCommandTextBuilder instance that generates CommandText for deleting rows.
Declaration
public static SpannerCommandTextBuilder CreateDeleteTextBuilder(string table)
Parameters
Type | Name | Description |
---|---|---|
string | table | The name of the Spanner database table from which rows will be deleted. Must not be null. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Delete Spanner command. |
CreateDmlTextBuilder(string)
Creates a SpannerCommandTextBuilder instance that generates CommandText for querying rows via a SQL query.
Declaration
public static SpannerCommandTextBuilder CreateDmlTextBuilder(string dmlStatement)
Parameters
Type | Name | Description |
---|---|---|
string | dmlStatement | The full SQL query. Must not be null or empty. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Select Spanner command. |
CreateInsertOrUpdateTextBuilder(string)
Creates a SpannerCommandTextBuilder instance that generates CommandText for inserting or updating rows.
Declaration
public static SpannerCommandTextBuilder CreateInsertOrUpdateTextBuilder(string table)
Parameters
Type | Name | Description |
---|---|---|
string | table | The name of the Spanner database table from which rows will be updated or inserted. Must not be null. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.InsertOrUpdate Spanner command. |
CreateInsertTextBuilder(string)
Creates a SpannerCommandTextBuilder instance that generates CommandText for inserting rows.
Declaration
public static SpannerCommandTextBuilder CreateInsertTextBuilder(string table)
Parameters
Type | Name | Description |
---|---|---|
string | table | The name of the Spanner database table from which rows will be inserted. Must not be null. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Insert Spanner command. |
CreateSelectTextBuilder(string)
Creates a SpannerCommandTextBuilder instance that generates CommandText for querying rows via a SQL query.
Declaration
public static SpannerCommandTextBuilder CreateSelectTextBuilder(string sqlQuery)
Parameters
Type | Name | Description |
---|---|---|
string | sqlQuery | The full SQL query. Must not be null or empty. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Select Spanner command. |
CreateUpdateTextBuilder(string)
Creates a SpannerCommandTextBuilder instance that generates CommandText for updating rows.
Declaration
public static SpannerCommandTextBuilder CreateUpdateTextBuilder(string table)
Parameters
Type | Name | Description |
---|---|---|
string | table | The name of the Spanner database table from which rows will be updated. Must not be null. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder representing a SpannerCommandType.Update Spanner command. |
FromCommandText(string)
Creates a SpannerCommandTextBuilder instance by parsing existing command text. The given text will be analyzed to choose the proper SpannerCommandType.
Declaration
public static SpannerCommandTextBuilder FromCommandText(string commandText)
Parameters
Type | Name | Description |
---|---|---|
string | commandText | The full command text containing a query, DDL statement or insert/update/delete operation. The given text will be parsed and validated. Must not be null. |
Returns
Type | Description |
---|---|
SpannerCommandTextBuilder | A SpannerCommandTextBuilder whose SpannerCommandType is determined
from parsing |
Remarks
If the intended SpannerCommandType is Select, then commandText
should be
a SQL Query. If the intended SpannerCommandType is Ddl, then this string should be
the DDL statement (eg 'CREATE TABLE MYTABLE...')
If the intended SpannerCommandType is Update, Delete,
InsertOrUpdate, or Insert, then the text should be '[spanner command type] [table name]'
such as 'INSERT MYTABLE'. Must not be null or empty.
Exceptions
Type | Condition |
---|---|
ArgumentException |
|
ToString()
Returns a string that represents the current object.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
string | A string that represents the current object. |