{"action":"created","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/17312","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/17312/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/17312/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/17312/events","html_url":"https://github.com/laravel/framework/pull/17312","id":200574407,"number":17312,"title":"[5.4] Can't Wrap DB Names Containing Spaces When Aliasing","user":{"login":"voidstate","id":1204122,"avatar_url":"https://avatars.githubusercontent.com/u/1204122?v=3","gravatar_id":"","url":"https://api.github.com/users/voidstate","html_url":"https://github.com/voidstate","followers_url":"https://api.github.com/users/voidstate/followers","following_url":"https://api.github.com/users/voidstate/following{/other_user}","gists_url":"https://api.github.com/users/voidstate/gists{/gist_id}","starred_url":"https://api.github.com/users/voidstate/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/voidstate/subscriptions","organizations_url":"https://api.github.com/users/voidstate/orgs","repos_url":"https://api.github.com/users/voidstate/repos","events_url":"https://api.github.com/users/voidstate/events{/privacy}","received_events_url":"https://api.github.com/users/voidstate/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-01-13T08:36:16Z","updated_at":"2017-01-13T10:17:16Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/laravel/framework/pulls/17312","html_url":"https://github.com/laravel/framework/pull/17312","diff_url":"https://github.com/laravel/framework/pull/17312.diff","patch_url":"https://github.com/laravel/framework/pull/17312.patch"},"body":"Database names containing spaces are perfectly legal in Microsoft SQL Server.\r\n\r\nCurrently, when using SQL Server, if you have a database which includes spaces, the grammar handles wrapping it fine.\r\n\r\nSo this:\r\n\r\nMy Sample Database.dbo.my_table.my_column\r\n\r\nCorrectly becomes:\r\n\r\n[My Sample Database].[dbo].[my_table].[my_column]\r\n\r\n*But* if you also try to alias a column when the database contains spaces, it breaks.\r\n\r\nThis:\r\n\r\nMy Sample Database.dbo.my_table.my_column AS my_aliased_column\r\n\r\nBecomes:\r\n\r\n[My] AS [Sample]\r\n\r\nI have traced the error to Database/Grammar/wrapAliasedValue() using explode( ' ' ) - the code thinks the spaces in the database name are the spaces around the \"AS\".\r\n\r\nWe can fix this by using regex instead of explode, splitting on the \"AS\" more accurately.\r\n\r\nJust replace the explode with this:\r\n\r\n$segments = preg_split( '/\\s+as\\s+/i', $value );\r\n\r\nNote: When you have an Eloquent belongsToMany method that has to include the database name (eg. we need to join across DBs), this type of alias is created automatically, generating this error.\r\n\r\nI originally committed this to 5.3 (https://github.com/laravel/framework/pull/17292) and was asked to commit here instead."},"comment":{"url":"https://api.github.com/repos/laravel/framework/issues/comments/272408866","html_url":"https://github.com/laravel/framework/pull/17312#issuecomment-272408866","issue_url":"https://api.github.com/repos/laravel/framework/issues/17312","id":272408866,"user":{"login":"GrahamCampbell","id":2829600,"avatar_url":"https://avatars.githubusercontent.com/u/2829600?v=3","gravatar_id":"","url":"https://api.github.com/users/GrahamCampbell","html_url":"https://github.com/GrahamCampbell","followers_url":"https://api.github.com/users/GrahamCampbell/followers","following_url":"https://api.github.com/users/GrahamCampbell/following{/other_user}","gists_url":"https://api.github.com/users/GrahamCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/GrahamCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GrahamCampbell/subscriptions","organizations_url":"https://api.github.com/users/GrahamCampbell/orgs","repos_url":"https://api.github.com/users/GrahamCampbell/repos","events_url":"https://api.github.com/users/GrahamCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/GrahamCampbell/received_events","type":"User","site_admin":false},"created_at":"2017-01-13T10:17:16Z","updated_at":"2017-01-13T10:17:16Z","body":"Please add tests to cover this."}}
{"actor":{"display_login":"GrahamCampbell"}}