Edit Data Service (#241)

This is a very large change. I'll try to outline what's going on.

1. This adds the **EditDataService** which manages editing **Sessions**.
    1. Each session has a **ResultSet** (from the QueryExecutionService) which has the rows of the table and basic metadata about the columns 
    2. Each session also has an **IEditTableMetadata** implementation which is derived from SMO metadata which provides more in-depth and trustworthy data about the table than SqlClient alone can.
    3. Each session holds a list of **RowEditBase** abstract class implementations
        1. **RowUpdate** - Update cells in a row (generates `UPDATE` statement)
        2. **RowDelete** - Delete an entire row (generates `DELETE` statement)
        3. **RowCreate** - Add a new row (generates `INSERT INTO` statement)
    4. Row edits have a collection of **CellUpdates** that hold updates for individual cells (except for RowDelete)
        1. Cell updates are generated from text
     5. RowEditBase offers some baseline functionality
        1. Generation of `WHERE` clauses (which can be parameterized)
        2. Validation of whether a column can be updated
2. New API Actions
    1. edit/initialize - Queries for the contents of a table/view, builds SMO metadata, sets up a session
    2. edit/createRow - Adds a new RowCreate to the Session
    3. edit/deleteRow - Adds a new RowDelete to the Session
    4. edit/updateCell - Adds a CellUpdate to a RowCreate or RowUpdate in the Session
    5. edit/revertRow - Removes a RowCreate, RowDelete, or RowUpdate from the Session
    6. edit/script - Generates a script for the changes in the Session and stores to disk
    7. edit/dispose - Removes a Session and releases the query
3. Smaller updates (unit test mock improvements, tweaks to query execution service)

**There are more updates planned -- this is just to get eyeballs on the main body of code**

* Initial stubs for edit data service

* Stubbing out update management code

* Adding rudimentary dispose request

* More stubbing out of update row code

* Adding complete edit command contracts, stubbing out request handlers

* Adding basic implementation of get script

* More in progress work to implement base of row edits

* More in progress work to implement base of row edits

* Adding string => object conversion logic and various cleanup

* Adding a formatter for using values in scripts

* Splitting IMessageSender into IEventSender and IRequestSender

* Adding inter-service method for executing queries

* Adding inter-service method for disposing of a query

* Changing edit contract to include the object to edit

* Fully fleshing out edit session initialization

* Generation of delete scripts is working

* Adding scripter for update statements

* Adding scripting functionality for INSERT statements

* Insert, Update, and Delete all working with SMO metadata

* Polishing for SqlScriptFormatter

* Unit tests and reworked byte[] conversion

* Replacing the awful and inflexible Dictionary<string, string>[][] with a much better test data set class

* Fixing syntax error in generated UPDATE statements

* Adding unit tests for RowCreate

* Adding tests for the row edit base class

* Adding row delete tests

* Adding RowUpdate tests, validation for number of key columns

* Adding tests for the unit class

* Adding get script tests for the session

* Service integration tests, except initialization tests

* Service integration tests, except initialization tests

* Adding messages to sr.strings

* Adding messages to sr.strings

* Fixing broken unit tests

* Adding factory pattern for SMO metadata provider

* Copyright and other comments

* Addressing first round of comments

* Refactoring EditDataService to have a single method for handling
session-dependent operations
* Refactoring Edit Data contracts to inherit from a Session and Row
operation params base class
* Copyright additions
* Small tweak to strings
* Updated unit tests to test the refactors

* More revisions as per pull request comments
This commit is contained in:
Benjamin Russell
2017-02-22 17:32:57 -08:00
committed by GitHub
parent 2b15890b00
commit 795eba3da6
49 changed files with 4370 additions and 137 deletions

View File

@@ -230,6 +230,15 @@ namespace Microsoft.SqlTools.ServiceLayer.Localization {
}
}
/// <summary>
/// Looks up a localized string similar to Specified URI &apos;{0}&apos; does not have a default connection.
/// </summary>
public static string ConnectionServiceDbErrorDefaultNotConnected {
get {
return ResourceManager.GetString("ConnectionServiceDbErrorDefaultNotConnected", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to SpecifiedUri &apos;{0}&apos; does not have existing connection.
/// </summary>

View File

@@ -485,6 +485,134 @@ namespace Microsoft.SqlTools.ServiceLayer
}
}
public static string EditDataSessionNotFound
{
get
{
return Keys.GetString(Keys.EditDataSessionNotFound);
}
}
public static string EditDataQueryNotCompleted
{
get
{
return Keys.GetString(Keys.EditDataQueryNotCompleted);
}
}
public static string EditDataQueryImproperResultSets
{
get
{
return Keys.GetString(Keys.EditDataQueryImproperResultSets);
}
}
public static string EditDataFailedAddRow
{
get
{
return Keys.GetString(Keys.EditDataFailedAddRow);
}
}
public static string EditDataRowOutOfRange
{
get
{
return Keys.GetString(Keys.EditDataRowOutOfRange);
}
}
public static string EditDataUpdatePending
{
get
{
return Keys.GetString(Keys.EditDataUpdatePending);
}
}
public static string EditDataUpdateNotPending
{
get
{
return Keys.GetString(Keys.EditDataUpdateNotPending);
}
}
public static string EditDataObjectMetadataNotFound
{
get
{
return Keys.GetString(Keys.EditDataObjectMetadataNotFound);
}
}
public static string EditDataInvalidFormatBinary
{
get
{
return Keys.GetString(Keys.EditDataInvalidFormatBinary);
}
}
public static string EditDataInvalidFormatBoolean
{
get
{
return Keys.GetString(Keys.EditDataInvalidFormatBoolean);
}
}
public static string EditDataCreateScriptMissingValue
{
get
{
return Keys.GetString(Keys.EditDataCreateScriptMissingValue);
}
}
public static string EditDataDeleteSetCell
{
get
{
return Keys.GetString(Keys.EditDataDeleteSetCell);
}
}
public static string EditDataColumnIdOutOfRange
{
get
{
return Keys.GetString(Keys.EditDataColumnIdOutOfRange);
}
}
public static string EditDataColumnCannotBeEdited
{
get
{
return Keys.GetString(Keys.EditDataColumnCannotBeEdited);
}
}
public static string EditDataColumnNoKeyColumns
{
get
{
return Keys.GetString(Keys.EditDataColumnNoKeyColumns);
}
}
public static string EditDataScriptFilePathNull
{
get
{
return Keys.GetString(Keys.EditDataScriptFilePathNull);
}
}
public static string EE_BatchSqlMessageNoProcedureInfo
{
get
@@ -790,6 +918,11 @@ namespace Microsoft.SqlTools.ServiceLayer
return Keys.GetString(Keys.WorkspaceServiceBufferPositionOutOfOrder, sLine, sCol, eLine, eCol);
}
public static string EditDataUnsupportedObjectType(string typeName)
{
return Keys.GetString(Keys.EditDataUnsupportedObjectType, typeName);
}
[System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Keys
{
@@ -1008,6 +1141,57 @@ namespace Microsoft.SqlTools.ServiceLayer
public const string WorkspaceServiceBufferPositionOutOfOrder = "WorkspaceServiceBufferPositionOutOfOrder";
public const string EditDataSessionNotFound = "EditDataSessionNotFound";
public const string EditDataUnsupportedObjectType = "EditDataUnsupportedObjectType";
public const string EditDataQueryNotCompleted = "EditDataQueryNotCompleted";
public const string EditDataQueryImproperResultSets = "EditDataQueryImproperResultSets";
public const string EditDataFailedAddRow = "EditDataFailedAddRow";
public const string EditDataRowOutOfRange = "EditDataRowOutOfRange";
public const string EditDataUpdatePending = "EditDataUpdatePending";
public const string EditDataUpdateNotPending = "EditDataUpdateNotPending";
public const string EditDataObjectMetadataNotFound = "EditDataObjectMetadataNotFound";
public const string EditDataInvalidFormatBinary = "EditDataInvalidFormatBinary";
public const string EditDataInvalidFormatBoolean = "EditDataInvalidFormatBoolean";
public const string EditDataCreateScriptMissingValue = "EditDataCreateScriptMissingValue";
public const string EditDataDeleteSetCell = "EditDataDeleteSetCell";
public const string EditDataColumnIdOutOfRange = "EditDataColumnIdOutOfRange";
public const string EditDataColumnCannotBeEdited = "EditDataColumnCannotBeEdited";
public const string EditDataColumnNoKeyColumns = "EditDataColumnNoKeyColumns";
public const string EditDataScriptFilePathNull = "EditDataScriptFilePathNull";
public const string EE_BatchSqlMessageNoProcedureInfo = "EE_BatchSqlMessageNoProcedureInfo";

View File

@@ -410,6 +410,75 @@
<comment>.
Parameters: 0 - sLine (int), 1 - sCol (int), 2 - eLine (int), 3 - eCol (int) </comment>
</data>
<data name="EditDataSessionNotFound" xml:space="preserve">
<value>Edit session does not exist.</value>
<comment></comment>
</data>
<data name="EditDataUnsupportedObjectType" xml:space="preserve">
<value>Database object {0} cannot be used for editing.</value>
<comment>.
Parameters: 0 - typeName (string) </comment>
</data>
<data name="EditDataQueryNotCompleted" xml:space="preserve">
<value>Query has not completed execution</value>
<comment></comment>
</data>
<data name="EditDataQueryImproperResultSets" xml:space="preserve">
<value>Query did not generate exactly one result set</value>
<comment></comment>
</data>
<data name="EditDataFailedAddRow" xml:space="preserve">
<value>Failed to add new row to update cache</value>
<comment></comment>
</data>
<data name="EditDataRowOutOfRange" xml:space="preserve">
<value>Given row ID is outside the range of rows in the edit cache</value>
<comment></comment>
</data>
<data name="EditDataUpdatePending" xml:space="preserve">
<value>An update is already pending for this row and must be reverted first</value>
<comment></comment>
</data>
<data name="EditDataUpdateNotPending" xml:space="preserve">
<value>Given row ID does not have pending updated</value>
<comment></comment>
</data>
<data name="EditDataObjectMetadataNotFound" xml:space="preserve">
<value>Table or view metadata could not be found</value>
<comment></comment>
</data>
<data name="EditDataInvalidFormatBinary" xml:space="preserve">
<value>Invalid format for binary column</value>
<comment></comment>
</data>
<data name="EditDataInvalidFormatBoolean" xml:space="preserve">
<value>Allowed values for boolean columns are 0, 1, "true", or "false"</value>
<comment></comment>
</data>
<data name="EditDataCreateScriptMissingValue" xml:space="preserve">
<value>A required cell value is missing</value>
<comment></comment>
</data>
<data name="EditDataDeleteSetCell" xml:space="preserve">
<value>A delete is pending for this row, a cell update cannot be applied.</value>
<comment></comment>
</data>
<data name="EditDataColumnIdOutOfRange" xml:space="preserve">
<value>Column ID must be in the range of columns for the query</value>
<comment></comment>
</data>
<data name="EditDataColumnCannotBeEdited" xml:space="preserve">
<value>Column cannot be edited</value>
<comment></comment>
</data>
<data name="EditDataColumnNoKeyColumns" xml:space="preserve">
<value>No key columns were found</value>
<comment></comment>
</data>
<data name="EditDataScriptFilePathNull" xml:space="preserve">
<value>An output filename must be provided</value>
<comment></comment>
</data>
<data name="EE_BatchSqlMessageNoProcedureInfo" xml:space="preserve">
<value>Msg {0}, Level {1}, State {2}, Line {3}</value>
<comment></comment>

View File

@@ -201,6 +201,43 @@ WorkspaceServicePositionColumnOutOfRange(int line) = Position is outside of colu
WorkspaceServiceBufferPositionOutOfOrder(int sLine, int sCol, int eLine, int eCol) = Start position ({0}, {1}) must come before or be equal to the end position ({2}, {3})
############################################################################
# Edit Data Service
EditDataSessionNotFound = Edit session does not exist.
EditDataUnsupportedObjectType(string typeName) = Database object {0} cannot be used for editing.
EditDataQueryNotCompleted = Query has not completed execution
EditDataQueryImproperResultSets = Query did not generate exactly one result set
EditDataFailedAddRow = Failed to add new row to update cache
EditDataRowOutOfRange = Given row ID is outside the range of rows in the edit cache
EditDataUpdatePending = An update is already pending for this row and must be reverted first
EditDataUpdateNotPending = Given row ID does not have pending updated
EditDataObjectMetadataNotFound = Table or view metadata could not be found
EditDataInvalidFormatBinary = Invalid format for binary column
EditDataInvalidFormatBoolean = Allowed values for boolean columns are 0, 1, "true", or "false"
EditDataCreateScriptMissingValue = A required cell value is missing
EditDataDeleteSetCell = A delete is pending for this row, a cell update cannot be applied.
EditDataColumnIdOutOfRange = Column ID must be in the range of columns for the query
EditDataColumnCannotBeEdited = Column cannot be edited
EditDataColumnNoKeyColumns = No key columns were found
EditDataScriptFilePathNull = An output filename must be provided
############################################################################
# DacFx Resources

View File

@@ -509,6 +509,92 @@
<target state="new">Replacement of an empty string by an empty string.</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataSessionNotFound">
<source>Edit session does not exist.</source>
<target state="new">Edit session does not exist.</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataQueryNotCompleted">
<source>Query has not completed execution</source>
<target state="new">Query has not completed execution</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataQueryImproperResultSets">
<source>Query did not generate exactly one result set</source>
<target state="new">Query did not generate exactly one result set</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataFailedAddRow">
<source>Failed to add new row to update cache</source>
<target state="new">Failed to add new row to update cache</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataRowOutOfRange">
<source>Given row ID is outside the range of rows in the edit cache</source>
<target state="new">Given row ID is outside the range of rows in the edit cache</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataUpdatePending">
<source>An update is already pending for this row and must be reverted first</source>
<target state="new">An update is already pending for this row and must be reverted first</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataUpdateNotPending">
<source>Given row ID does not have pending updated</source>
<target state="new">Given row ID does not have pending updated</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataObjectMetadataNotFound">
<source>Table or view metadata could not be found</source>
<target state="new">Table or view metadata could not be found</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataInvalidFormatBinary">
<source>Invalid format for binary column</source>
<target state="new">Invalid format for binary column</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataInvalidFormatBoolean">
<source>Allowed values for boolean columns are 0, 1, "true", or "false"</source>
<target state="new">Boolean columns must be numeric 1 or 0, or string true or false</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataCreateScriptMissingValue">
<source>A required cell value is missing</source>
<target state="new">A required cell value is missing</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataDeleteSetCell">
<source>A delete is pending for this row, a cell update cannot be applied.</source>
<target state="new">A delete is pending for this row, a cell update cannot be applied.</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataColumnIdOutOfRange">
<source>Column ID must be in the range of columns for the query</source>
<target state="new">Column ID must be in the range of columns for the query</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataColumnCannotBeEdited">
<source>Column cannot be edited</source>
<target state="new">Column cannot be edited</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataColumnNoKeyColumns">
<source>No key columns were found</source>
<target state="new">No key columns were found</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataScriptFilePathNull">
<source>An output filename must be provided</source>
<target state="new">An output filename must be provided</target>
<note></note>
</trans-unit>
<trans-unit id="EditDataUnsupportedObjectType">
<source>Database object {0} cannot be used for editing.</source>
<target state="new">Database object {0} cannot be used for editing.</target>
<note>.
Parameters: 0 - typeName (string) </note>
</trans-unit>
</body>
</file>
</xliff>