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

This commit is contained in:
Ansgar Becker
2013-01-19 12:43:41 +00:00
parent 88b3666bf1
commit cd75b0899d
3 changed files with 22 additions and 6 deletions

View File

@ -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);

View File

@ -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

View File

@ -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;