mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
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:
@ -36,6 +36,7 @@ type
|
|||||||
function IsSameAs(CompareTo: TDBObject): Boolean;
|
function IsSameAs(CompareTo: TDBObject): Boolean;
|
||||||
function QuotedDatabase(AlwaysQuote: Boolean=True): String;
|
function QuotedDatabase(AlwaysQuote: Boolean=True): String;
|
||||||
function QuotedName(AlwaysQuote: Boolean=True): String;
|
function QuotedName(AlwaysQuote: Boolean=True): String;
|
||||||
|
function QuotedDbAndTableName(AlwaysQuote: Boolean=True): String;
|
||||||
function QuotedColumn(AlwaysQuote: Boolean=True): String;
|
function QuotedColumn(AlwaysQuote: Boolean=True): String;
|
||||||
property ObjType: String read GetObjType;
|
property ObjType: String read GetObjType;
|
||||||
property ImageIndex: Integer read GetImageIndex;
|
property ImageIndex: Integer read GetImageIndex;
|
||||||
@ -4642,9 +4643,13 @@ var
|
|||||||
db: String;
|
db: String;
|
||||||
begin
|
begin
|
||||||
// Return `db`.`table` if necessairy, otherwise `table`
|
// Return `db`.`table` if necessairy, otherwise `table`
|
||||||
|
Result := '';
|
||||||
db := DatabaseName;
|
db := DatabaseName;
|
||||||
if Connection.Database <> db then
|
if Connection.Database <> db then begin
|
||||||
Result := Connection.QuoteIdent(db)+'.';
|
Result := Connection.QuoteIdent(db)+'.';
|
||||||
|
if Connection.Parameters.NetTypeGroup = ngMSSQL then
|
||||||
|
Result := Result + Connection.QuoteIdent('dbo')+'.';
|
||||||
|
end;
|
||||||
Result := Result + Connection.QuoteIdent(TableName);
|
Result := Result + Connection.QuoteIdent(TableName);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -4964,6 +4969,14 @@ begin
|
|||||||
Result := Connection.QuoteIdent(Name, AlwaysQuote);
|
Result := Connection.QuoteIdent(Name, AlwaysQuote);
|
||||||
end;
|
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;
|
function TDBObject.QuotedColumn(AlwaysQuote: Boolean=True): String;
|
||||||
begin
|
begin
|
||||||
Result := Connection.QuoteIdent(Column, AlwaysQuote);
|
Result := Connection.QuoteIdent(Column, AlwaysQuote);
|
||||||
|
@ -4255,10 +4255,7 @@ begin
|
|||||||
// Cut last comma
|
// Cut last comma
|
||||||
Delete(Select, Length(Select)-1, 2);
|
Delete(Select, Length(Select)-1, 2);
|
||||||
// Include db name for cases in which dbtree is switching databases and pending updates are in process
|
// Include db name for cases in which dbtree is switching databases and pending updates are in process
|
||||||
Select := Select + ' FROM '+DBObj.Connection.QuoteIdent(ActiveDatabase)+'.';
|
Select := Select + ' FROM '+DBObj.QuotedDbAndTableName;
|
||||||
if DBObj.Connection.Parameters.NetTypeGroup = ngMSSQL then
|
|
||||||
Select := Select + DBObj.Connection.QuoteIdent('dbo') + '.';
|
|
||||||
Select := Select + DBObj.QuotedName;
|
|
||||||
|
|
||||||
// Append WHERE clause
|
// Append WHERE clause
|
||||||
if SynMemoFilter.GetTextLen > 0 then begin
|
if SynMemoFilter.GetTextLen > 0 then begin
|
||||||
|
@ -1391,7 +1391,13 @@ begin
|
|||||||
Output('DELETE FROM '+TargetDbAndObject, True, True, True, True, True);
|
Output('DELETE FROM '+TargetDbAndObject, True, True, True, True, True);
|
||||||
Output('/*!40000 ALTER TABLE '+TargetDbAndObject+' DISABLE KEYS */', True, True, True, True, True);
|
Output('/*!40000 ALTER TABLE '+TargetDbAndObject+' DISABLE KEYS */', True, True, True, True, True);
|
||||||
while true do begin
|
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);
|
Inc(Offset, Limit);
|
||||||
if Data.RecordCount = 0 then
|
if Data.RecordCount = 0 then
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user