Class SpannerCommandTextBuilder (3.5.0)

public sealed class SpannerCommandTextBuilder

Builds the CommandText string for executing a query or operation on a Spanner database. Instances are constructed with static factory methods.

Inheritance

Object > SpannerCommandTextBuilder

Namespace

Google.Cloud.Spanner.Data

Assembly

Google.Cloud.Spanner.Data.dll

Properties

CommandText

public string CommandText { get; }

Gets the resulting string to be used for CommandText.

Property Value
TypeDescription
String

ExtraStatements

public IReadOnlyList<string> ExtraStatements { get; }

A set of additional statements to execute if supported by the command.

Property Value
TypeDescription
IReadOnlyList<String>

SpannerCommandType

public SpannerCommandType SpannerCommandType { get; }

Gets the type of Spanner command (Select, Update, Delete, InsertOrUpdate, Insert, Ddl, Dml).

Property Value
TypeDescription
SpannerCommandType

TargetTable

public string TargetTable { get; }

Returns the target Spanner database table if the command is Update, Delete, InsertOrUpdate, or Insert, or null otherwise.

Property Value
TypeDescription
String

Methods

CreateDdlTextBuilder(String, String[])

public static SpannerCommandTextBuilder CreateDdlTextBuilder(string ddlStatement, params string[] extraDdlStatements)

Creates a SpannerCommandTextBuilder instance that generates CommandText for executing a DDL statement.

Parameters
NameDescription
ddlStatementString

The full DDL statement. Must not be null.

extraDdlStatementsString[]

An optional set of additional DDL statements to execute after the first statement. Extra Ddl statements cannot be used to create additional databases.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.Ddl Spanner command.

CreateDeleteTextBuilder(String)

public static SpannerCommandTextBuilder CreateDeleteTextBuilder(string table)

Creates a SpannerCommandTextBuilder instance that generates CommandText for deleting rows.

Parameter
NameDescription
tableString

The name of the Spanner database table from which rows will be deleted. Must not be null.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.Delete Spanner command.

CreateDmlTextBuilder(String)

public static SpannerCommandTextBuilder CreateDmlTextBuilder(string dmlStatement)

Creates a SpannerCommandTextBuilder instance that generates CommandText for querying rows via a SQL query.

Parameter
NameDescription
dmlStatementString

The full SQL query. Must not be null or empty.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.Select Spanner command.

CreateInsertOrUpdateTextBuilder(String)

public static SpannerCommandTextBuilder CreateInsertOrUpdateTextBuilder(string table)

Creates a SpannerCommandTextBuilder instance that generates CommandText for inserting or updating rows.

Parameter
NameDescription
tableString

The name of the Spanner database table from which rows will be updated or inserted. Must not be null.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.InsertOrUpdate Spanner command.

CreateInsertTextBuilder(String)

public static SpannerCommandTextBuilder CreateInsertTextBuilder(string table)

Creates a SpannerCommandTextBuilder instance that generates CommandText for inserting rows.

Parameter
NameDescription
tableString

The name of the Spanner database table from which rows will be inserted. Must not be null.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.Insert Spanner command.

CreateSelectTextBuilder(String)

public static SpannerCommandTextBuilder CreateSelectTextBuilder(string sqlQuery)

Creates a SpannerCommandTextBuilder instance that generates CommandText for querying rows via a SQL query.

Parameter
NameDescription
sqlQueryString

The full SQL query. Must not be null or empty.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.Select Spanner command.

CreateUpdateTextBuilder(String)

public static SpannerCommandTextBuilder CreateUpdateTextBuilder(string table)

Creates a SpannerCommandTextBuilder instance that generates CommandText for updating rows.

Parameter
NameDescription
tableString

The name of the Spanner database table from which rows will be updated. Must not be null.

Returns
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder representing a SpannerCommandType.Update Spanner command.

FromCommandText(String)

public static SpannerCommandTextBuilder FromCommandText(string commandText)

Creates a SpannerCommandTextBuilder instance by parsing existing command text. The given text will be analyzed to choose the proper SpannerCommandType.

Parameter
NameDescription
commandTextString

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
TypeDescription
SpannerCommandTextBuilder

A SpannerCommandTextBuilder whose SpannerCommandType is determined from parsing commandText.

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
TypeDescription
ArgumentException

commandText is not formatted correctly.

ToString()

public override string ToString()
Returns
TypeDescription
String
Overrides