Commit Graph

484 Commits

Author SHA1 Message Date
Benjamin Russell
16b3874f28 Remove SELECT * from edit/initialize Query (#288)
* Major refactor of EditDataMetadata providers

* EditMetadataFactory generates "basic" EditTableMetadata objects based entirely on SMO metadata
* SmoEditTableMetadata no longer depends on SMO, making it unecessary to mock it
* Renamed SmoEditTableMetadata to EditTableMetadata
* EditTableMetadata can be extended with DbColumnWrappers

* Moving logic for extending a EditColumnMetadata into that class

* I *think* this will work for async execution of initialize tasks

* Fixing unit tests for new Edit(Table|Column)Metadata classes

* Async stuff that works! And passes unit tests

* Adding unit tests
Adding .idea to gitignore

* Adding message to the EditSessionReadyEvent

* Fixes from dev merge

* Fixing unit tests that Rider didn't catch as failing
May have been a bit heavy-handed with the async/await stuff

* Couple changes as per PR comments
2017-03-22 10:53:24 -07:00
Benjamin Russell
d7ecfb1a87 feature/edit/subset (#283)
* Changing query/subset API to only use Result on success, Error on error

* Creating an interservice API for getting query result subsets

* Updates to subset API

* RowStartIndex is now long
* Output of query/subset is a 2D array of DbCellValue
* Adding LongSkip method to LongList to allow skipping ahead by longs
* Moving LongList back to ServiceLayer utilities. Move refactoring

* Stubbing out request for edit/subset

* Initial implementation of getting edit rows

* Unit tests for RowEdit and RowDelete .GetEditRow

* Fixing major bugs in LongList implementation, adding much more thorough tests

* Adding some more unit tests and fixes to make unit tests pass

* Fixing comment
2017-03-21 15:14:04 -07:00
Leila Lali
9e576dea92 Added options to connection parameter (#285)
* Added options to connection parameter
2017-03-21 13:22:29 -07:00
Karl Burtram
addad29b7c Add Scripter class and use it in the ScriptingService (#286)
* Initial scripting commit

* Fix the script CREATE integration test

* Use language service binding queue for scripting

* Update scripting service to have methods for each operation

* Add scripter class

* Fix build break.

* Fix a few bugs

* Use scripter class instead of PeekDefinition class.

* Fix scripting test break

* Fix header incorrectly saying file is generated.

* Add localization tests to address a large block of code not covered by automation.

* Moving system usings to top of using list
2017-03-21 13:18:52 -07:00
Karl Burtram
1150a19eae Update cake to use JSON.Net 9.0.1 to fix build break (#287) 2017-03-21 13:01:36 -07:00
Kevin Cunnane
844358a19c Bump SMO to SSMS 17.0 RC3 bits (#284)
* Bump SMO bits to align with 17.0 RC3 release

* Add updated SMO binary

* Fix formatter failures caused by SqlProc breaking changes
- Changes to SqlProcedureDefinition subclasses mean that the definition starts at "Create Procedure" instead of after it. This highlighted an issue where the prefix region handling was via comma separated list (which adds newlines to the prefix region) instead of newline separated list (which does not).
- Changed the structure to use the 2 different formatters for relevant regions, and verified all tests now pass.
- Also removed unnnecessary Export clause from the SqlTableDefinitionFormatter, since this was spotted during debugging

* Fix sample project.json dependencies
- Fix up the dependencies in our samples as this was failing the build on TravisCI. Should consider in the future whether or not we want to exclude these from CI runs, but for now the benefit is that we're forced to keep the samples up to date.
2017-03-20 14:23:00 -07:00
Wujun Zhou
8d47d5c7b3 Save As Excel (#279)
* Fix dispose pattern usage in SaveAsWriterBase

* Add SaveAsExcel feature

This adds the save as excel function to the backend. To reduce large dependency and run on dotnet core now, this implementation use a raw excel writer (the SaveAsExcelFileStreamWriterHelper.cs) instrad of popular excel library, such as EPPlus or OpenXmlSdk.

* Fix can not open the generated excel file in google sheet

For the file name inside excel, google uses a case sensitive path while
Excel doesn't. This change fix the case, so that the file name matches
the one in x1/_rels/workbook.xml.rels

* Fix datetime doesn't recognized by google sheet

Google doesn't support cell type t="d" with ISO 8601 date. (From stackoverflow thread and testing), thus use the old way of excel datetime, which uses double to present datetime

* update to use xmlwriter

* Add basic unit tests for SaveAsExcelFileStreamWriterHelper

* refactor: simplify the public interface of the SaveAsExcelFileStreamWriterHelper

* update private fields names based on the name convention

* Add comments to classes of SaveAsExcel feature

* clean up SaveAsExcelFileStreamWriterHelper

- change SaveAsExcelFileStreamWriterHelper from public to internal
- remove the PenddingRowEndTag function from referenceManager
- change the SaveAsExcelFileStreamWriterHelper(stream) to default leaveOpen to false to match the normal behavior
- change the rowreference to use XmlConvert to convert int to string
- rename writeSetting to writerSetting and add private

* fix CI test error for SaveAsExcel

* remove ExporterException in SaveAsExcel

* fix lefe over CSV to Excel in the comments

* refactor to be consistent with JsonWriter and remove the comment

* remove commented out test

The test is too slow to run

* fix typo in comment

* refactor SaveAsExcel to the coding standard

* refactor rewrite the WriteStyle with XmlWriter

* Add licence header

* reverse mistakenly checked-in changes

* fix: left-over CSV in commets

* remove duplicate check

The check was done in the IncreaseColumnReference, but that check is too late in case of too many columns. All the addCell do the check at the begining now

* fix TimeSpan more than 24 hours

* fix AddRowMustBeCalledBeforeAddCellException test

This is  due to remove duplicate call to AssureColumnReference in  WriteAndIncreaseColumnReference

* fix: TimeSpan will write twice

* style: change retun in the switch to break

* Add bool format

* remove todo in comment

This provides extra safeguard in the cost of one memory access when null.
2017-03-16 14:33:12 -07:00
Kevin Cunnane
8d017368f9 Fixes #721 (#282)
- Ensure minimum of 2 newlines after GO statement
- All existing unit tests are passing, indicating this is respecting scenarios where users have comment lines after GO statements (this happens in many other tests)
2017-03-16 10:20:22 -07:00
Karl Burtram
7ba2011a1e Initial metadata and scripting services (#280)
* Initial metadata service and scripting service files

* Simple metadata lookup with SMO objects

* Add metadata type class

* Remove SMO from metadata service.

* Cleanup metadata service SQL

* Initial MetadataService test

* Add scripting commands

* Add metadata test case

* Remove sleep used for testing

* Use random table name in metadata test

* Add scripting tests
2017-03-14 22:35:17 -07:00
Brian O'Neill
9b1e07907e Add nuget package SqlScriptPublishModel. (#277)
The SqlScriptPublishModel is the model behind the SSMS scripting wizard. It has been ported to .NET Core to enable scripting scenarios to SqlToolsService. This change adds the SqlScriptPublishModel nuget package to the checked in packages in the bin\nuget folder.
2017-03-13 13:08:27 -07:00
Benjamin Russell
471e64fb1c Adding validation of timespan columns w/in 24hrs (#275)
Very small feature add to make sure that values entered for `TIME` columns are < 24hrs. If the value is >=24hrs when setting the column, an exception will be thrown that the edit/updateCell handler will catch and convert into an error on the JSON RPC side.

* Adding validation of timespan columns

* Fixing a merge conflict
2017-03-10 13:46:13 -08:00
Aditya Bist
125fe8b0e7 removed mono dependency (#276) 2017-03-09 18:02:42 -08:00
Benjamin Russell
f2afa07a93 NULL column validation when updating cells (#274)
* Adding validation that NULL is allowed when setting cell values

* Adding unit tests
2017-03-09 16:14:25 -08:00
Karl Burtram
8f3e83b519 Add nvarchar to IntelliSense keyword list (#272) 2017-03-09 14:33:43 -08:00
Karl Burtram
41a2564921 Add GroupName property to ConnectionOptions (#273) 2017-03-08 18:20:43 -08:00
Benjamin Russell
c0468e763f edit/revertCell (#268)
// edit/dispose -------------------------------------------------------------------------------
export interface EditDisposeParams extends IEditSessionOperationParams { }
export interface EditDisposeResult { }

* Initial plumbing for edit/revertCell

* Implementation of revert cell in the parents of the row edit base

* Adding unit tests
2017-03-08 14:49:13 -08:00
Karl Burtram
666ee98582 Add description field to ConnectionOption object (#271) 2017-03-08 14:09:12 -08:00
Benjamin Russell
056a08cd1b edit/createRow Default Values (#266)
Returns strings for the default value of a column when a new row is created. The values that could come back:
* `null` when there isn't a default for the column
* a string when there is a default for the column
* a placeholder (currently <TBD>) when the column cannot be updated

* Renaming EditTableMetadata to reflect its SMO source

* Implementation of returning default values

* Unit test for default values

* Reworking column defaults using default constraints

* Adding unit test for new sql script unwrapper

* Disabling flaky test

* Fixing oddities in tests, removing personal tests

* Fixing broken unit test
2017-03-08 13:51:38 -08:00
Benjamin Russell
29d27c2341 Block Initializing Edit Sessions When In Progress (#265)
* Implementation of a wait handle for initialize

* WIP

* Adding more initialize unit tests
2017-03-07 12:27:48 -08:00
Karl Burtram
17d2d825eb Provide connection options to host process (#267)
* Stage changes to other machine

* Add connection options in init message

* Fix option type
2017-03-07 11:00:52 -08:00
Kevin Cunnane
4de152847e Merge pull request #270 from Microsoft/merge/master
Merge master release 0.3.0 into Dev
2017-03-06 22:33:14 -08:00
Kevin Cunnane
adcc5c8089 Merge latest Dev and latest master 2017-03-06 17:59:41 -08:00
Kevin Cunnane
0f706f28ee Merge from Master 2017-03-06 17:56:04 -08:00
Benjamin Russell
ef3100de3b Changing test projects to UnitTests, fixing peek definition codegen bug (#269) 2017-03-06 17:55:48 -08:00
Raymond Martin
228b5b3748 Adding new 100% loc files (#264) 2017-03-06 17:23:27 -08:00
Benjamin Russell
52ac038ebe edit/commit Command (#262)
The main goal of this feature is to enable a command that will
1) Generate a parameterized command for each edit that is in the session
2) Execute that command against the server
3) Update the cached results of the table/view that's being edited with the committed changes (including computed/identity columns)

There's some secret sauce in here where I cheated around worrying about gaps in the updated results. This was accomplished by implementing an IComparable for row edit objects that ensures deletes are the *last* actions to occur and that they occur from the bottom of the list up (highest row ID to lowest). Thus, all other actions that are dependent on the row ID are performed first, then the largest row ID is deleted, then next largest, etc. Nevertheless, by the end of a commit the associated ResultSet is still the source of truth. It is expected that the results grid will need updating once changes are committed.

Also worth noting, although this pull request supports a "many edits, one commit" approach, it will work just fine for a "one edit, one commit" approach.

* WIP

* Adding basic commit support. Deletions work!

* Nailing down the commit logic, insert commits work!

* Updates work!

* Fixing bug in DbColumnWrapper IsReadOnly setting

* Comments

* ResultSet unit tests, fixing issue with seeking in mock writers

* Unit tests for RowCreate commands

* Unit tests for RowDelete

* RowUpdate unit tests

* Session and edit base tests

* Fixing broken unit tests

* Moving constants to constants file

* Addressing code review feedback

* Fixes from merge issues, string consts

* Removing ad-hoc code

* fixing as per @abist requests

* Fixing a couple more issues
2017-03-03 15:47:47 -08:00
Karl Burtram
f00136cffb Fix namespaces for code moved to separate class libraries (#263)
* Create ServiceHost a service-specific class

* Renaming hosting namespace

* Rename credentials namespace

* Fix namespaces
2017-03-02 14:41:06 -08:00
Benjamin Russell
1166778249 Isolate Shared Test Code (#252)
The goal of this make sure that test code is correctly organized to ensure that test suites aren't dependent on each other.
* UnitTests get their own project now (renaming Microsoft.SqlTools.ServiceLayer.Test to Microsoft.SqlTools.ServiceLayer.UnitTests) which is about 90% of the changes to the files.
* IntegrationTests no longer depends on UnitTests, only Test.Common
* Any shared components from TestObjects that spins up a "live" connection has been moved to IntegrationTests Utility/LiveConnectionHelper.cs
* The dictionary-based mock file stream factory has been moved to Test.Common since it is used by UnitTests and IntegrationTests
    * Added a overload that doesn't take a dictionary for when we don't care about monitoring the storage (about 90% of the time)
* The RunIf* wrapper methods have been moved to Test.Common
* OwnerUri and StandardQuery constants have been moved to Test.Common Constants file

* Updating to latest SDK version available at https://www.microsoft.com/net/core#windowscmd

* Moving unit tests to unit test folder

* Changing namespaces to UnitTests

* Moving some constants and shared functionality into common project, making the UnitTests reference it

* Unit tests are working!

* Integration tests are working

* Updating automated test runs

* Fixing one last broken unit test

* Exposing internals for other projects

* Moving edit data tests to UnitTest project

* Applying refactor fixes to unit tests

* Fixing flaky test that wasn't awaiting completion
2017-03-02 13:00:31 -08:00
Karl Burtram
f9abe5f0bd Remove hosting project from build script (#259) 2017-03-02 00:40:49 -08:00
Aditya Bist
a54404aa5b Fix/batch parser tests (#261)
* changing files to CRLF to change all files to LF

* changed all files to LF

* build on appveyor for the PR

* fixed trace directory path
2017-03-01 13:54:51 -08:00
Karl Burtram
213de5cc12 Don't crash when refreshing IntelliSense cache disconnected (#260)
* Prevent null ref exception in refresh cache handler

* Send refresh complete event when disconnected

* Wrap handler in global try/catch
2017-02-28 23:46:02 -08:00
Karl Burtram
0d99b36cc1 Don't crash when refreshing IntelliSense cache disconnected (#260)
* Prevent null ref exception in refresh cache handler

* Send refresh complete event when disconnected

* Wrap handler in global try/catch
2017-02-28 16:15:11 -08:00
Aditya Bist
74ba68053b Fix/batch parser tests (#256)
* changing files to CRLF to change all files to LF

* changed all files to LF

* build on appveyor for the PR
2017-02-28 11:55:53 -08:00
Kevin Cunnane
dd9f2d55d4 Fix DW connection bug (#258)
- Connection info cache is now per-DB instead of per-server. This has the downside of increasing #queries, but is required in order to correctly handle isSqlDW since this changes for each database on an Azure server.
2017-02-27 23:13:36 -08:00
Benjamin Russell
752b9dbbd0 Applying changes (#257) 2017-02-27 14:10:11 -08:00
Aditya Bist
25c5c27a6e Fix batch parser test (#239)
* fixed batch parser test

* fix batch parser test

* fix batch parser test

* fixed baseline tests for parser and fixed trace output logic

* Update RunEnvironmentInfo.cs

* checking error logs on AppVeyor

* checking error logs on app veyor

* changed file reading encoding

* adding logs to app veyor build

* changed encoding of baseline files

* added error logs for app veyor

* changed error logs for app veyor

* changed how file stream works in batch parser tests

* changed baseline and testscript encodings

* cleaned code for necessary batch parser tests
2017-02-24 15:49:45 -08:00
Kevin Cunnane
b38c1f2a42 Remove duplicate PeekDefinition telemetry event (#255) 2017-02-24 13:10:03 -08:00
Kevin Cunnane
ab70218249 Remove duplicate PeekDefinition telemetry event (#255) 2017-02-24 13:08:51 -08:00
Karl Burtram
3516a05f80 Fix MEF loader issues with framework assemblies (#253)
This is fixing a crashing bug in previous check-in so I'm pushing in.  Please leave comments on the commit and email if there is feedback.

* Fix MEF loader issues with framework assemblies

* Fix broken test from changed behavior

* Fix braces to C# convention
2017-02-23 19:18:43 -08:00
Karl Burtram
fdca9fa220 Handle open\close document events with git URI prefix (#254) 2017-02-23 18:16:58 -08:00
Karl Burtram
206cde9a3e Handle open\close document events with git URI prefix (#254) 2017-02-23 18:10:57 -08:00
Karl Burtram
0af7bef66d Create MS.SqlTools.Credentials project (#249)
* Initial credential service files

* Clean-up hostloader

* Update build scripts to build credentials archive

* Move hosting files to new assembly

* Add credentials files to MS.SqlTools.Credentials

* Remove duplicate files

* Update namespace in program.cs

* Fix test build breaks

* Update extensions visibility.

* Remove unused resource strings

* Add xproj files to SLN for appveyor builds

* Fix appveyor build break in test project

* Fix extensibility tests

* Fix various typos in latest iteration

* Add settings for Integration build

* Fix codecoverage.bat to use full pdb for new projects

* Fix bug when packing in folder with native images

* Fix typos in xproj

* Reset XLF to fix build.cmd
2017-02-23 16:09:58 -08:00
Benjamin Russell
e79a37bdfe Fix/update net core sdk (#251)
* Updating to latest SDK version available at https://www.microsoft.com/net/core#windowscmd

* Rolling back to preview2-003156

preview2-1-003177 has a bug where discovery of tests fails with null
exception
preview2-003156 is the latest SDK version on
https://www.microsoft.com/net/download/core (which surprisingly differs
from the version on the front page of .NET Core page)
2017-02-23 13:47:48 -08:00
Kevin Cunnane
e920c9212b System.Composition not compatible with NetCore 1.0 (#250)
- Reverting to a beta version of System.Composition that is compatible with NetCore 1.1. Otherwise we end up with a mishmash of versions which breaks Mac OpenSSL support
2017-02-22 17:47:17 -08:00
Kevin Cunnane
1b6e92d691 System.Composition not compatible with NetCore 1.0 (#250)
- Reverting to a beta version of System.Composition that is compatible with NetCore 1.1. Otherwise we end up with a mishmash of versions which breaks Mac OpenSSL support
2017-02-22 17:45:30 -08:00
Benjamin Russell
795eba3da6 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
2017-02-22 17:32:57 -08:00
Benjamin Russell
2b15890b00 Exposing the DisplayBitAsNumber setting (#248)
* Exposing the DisplayBitAsNumber setting

* Properly wiring up the settings for query execution service

* Fixing broken unit test
2017-02-22 14:31:29 -08:00
Kevin Cunnane
0c0bd3125b PlaceCommasBeforeNextStatement should handle correctly formatted text (#247)
- Fixed handling of PlaceCommasBeforeNextStatement so that it doesn't add whitespace unnecessarily. This ensures that repeated formats of the same text shouldn't keep adding whitespace
- Added tests covering a number of scenarios related to this
2017-02-22 11:08:57 -08:00
Kevin Cunnane
7f20f84add Avoid unnecessary indents for compount boolean expressions (#246)
- Avoid incrementing indents for compound binary boolean expressions. Multiple 'AND x = Y' statements were each indenting instead of having the same indent level.
- Fixes https://github.com/Microsoft/vscode-mssql/issues/709
2017-02-21 22:18:01 -08:00
Kevin Cunnane
e1c8cc5ac3 Formatter and PeekDefinition Telemetry (#245)
- Add telemetry point for format requests
- Update PeekDefinition telemetry so that it captures whether the attempt succeeded and if it was connected. This will help us understand whether our current behavior of just notifying success/failure to the output window was useful or not. It will also help us understand whether we're doing a good job implementing this / if we need to improve reliability and preformance.
2017-02-21 21:26:10 -08:00