From cd75b0899d04fd7aa3300f30ea9728b71834bdb0 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Sat, 19 Jan 2013 12:43:41 +0000 Subject: [PATCH] Quote db and table name in new function TDBObject.QuotedDbAndTableName, which also adds "dbo" for MS SQL inbetween. Plus, run SELECT in SQL export through ApplyLimitClause, to fix an SQL error on MS SQL. See http://www.heidisql.com/forum.php?t=11956 --- source/dbconnection.pas | 15 ++++++++++++++- source/main.pas | 5 +---- source/tabletools.pas | 8 +++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index a4679169..dae3d745 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -36,6 +36,7 @@ type function IsSameAs(CompareTo: TDBObject): Boolean; function QuotedDatabase(AlwaysQuote: Boolean=True): String; function QuotedName(AlwaysQuote: Boolean=True): String; + function QuotedDbAndTableName(AlwaysQuote: Boolean=True): String; function QuotedColumn(AlwaysQuote: Boolean=True): String; property ObjType: String read GetObjType; property ImageIndex: Integer read GetImageIndex; @@ -4642,9 +4643,13 @@ var db: String; begin // Return `db`.`table` if necessairy, otherwise `table` + Result := ''; db := DatabaseName; - if Connection.Database <> db then + if Connection.Database <> db then begin Result := Connection.QuoteIdent(db)+'.'; + if Connection.Parameters.NetTypeGroup = ngMSSQL then + Result := Result + Connection.QuoteIdent('dbo')+'.'; + end; Result := Result + Connection.QuoteIdent(TableName); end; @@ -4964,6 +4969,14 @@ begin Result := Connection.QuoteIdent(Name, AlwaysQuote); end; +function TDBObject.QuotedDbAndTableName(AlwaysQuote: Boolean=True): String; +begin + Result := QuotedDatabase(AlwaysQuote) + '.'; + if Connection.Parameters.NetTypeGroup = ngMSSQL then + Result := Result + Connection.QuoteIdent('dbo', AlwaysQuote) + '.'; + Result := Result + QuotedName(AlwaysQuote); +end; + function TDBObject.QuotedColumn(AlwaysQuote: Boolean=True): String; begin Result := Connection.QuoteIdent(Column, AlwaysQuote); diff --git a/source/main.pas b/source/main.pas index 0a9ddfe2..81a3650a 100644 --- a/source/main.pas +++ b/source/main.pas @@ -4255,10 +4255,7 @@ begin // Cut last comma Delete(Select, Length(Select)-1, 2); // Include db name for cases in which dbtree is switching databases and pending updates are in process - Select := Select + ' FROM '+DBObj.Connection.QuoteIdent(ActiveDatabase)+'.'; - if DBObj.Connection.Parameters.NetTypeGroup = ngMSSQL then - Select := Select + DBObj.Connection.QuoteIdent('dbo') + '.'; - Select := Select + DBObj.QuotedName; + Select := Select + ' FROM '+DBObj.QuotedDbAndTableName; // Append WHERE clause if SynMemoFilter.GetTextLen > 0 then begin diff --git a/source/tabletools.pas b/source/tabletools.pas index 79801888..3a35abec 100644 --- a/source/tabletools.pas +++ b/source/tabletools.pas @@ -1391,7 +1391,13 @@ begin Output('DELETE FROM '+TargetDbAndObject, True, True, True, True, True); Output('/*!40000 ALTER TABLE '+TargetDbAndObject+' DISABLE KEYS */', True, True, True, True, True); while true do begin - Data := DBObj.Connection.GetResults('SELECT * FROM '+DBObj.QuotedDatabase+'.'+DBObj.QuotedName+' LIMIT '+IntToStr(Offset)+', '+IntToStr(Limit)); + Data := DBObj.Connection.GetResults( + DBObj.Connection.ApplyLimitClause( + 'SELECT', + '* FROM '+DBObj.QuotedDbAndTableName, + Limit, + Offset) + ); Inc(Offset, Limit); if Data.RecordCount = 0 then break;