forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f821fbb
commit 189652d
Showing
32 changed files
with
200 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
#include <QDialog> | ||
|
||
#include "sql/sqlitetypes.h" | ||
#include "sql/ObjectIdentifier.h" | ||
|
||
class DBBrowserDB; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
#include <QHeaderView> | ||
#include <vector> | ||
|
||
class QLineEdit; | ||
class QTableView; | ||
class FilterLineEdit; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include "ObjectIdentifier.h" | ||
|
||
#include <regex> | ||
|
||
namespace sqlb { | ||
|
||
static escapeQuoting customQuoting = DoubleQuotes; | ||
|
||
void setIdentifierQuoting(escapeQuoting toQuoting) | ||
{ | ||
customQuoting = toQuoting; | ||
} | ||
|
||
std::string escapeIdentifier(const std::string& id) | ||
{ | ||
switch(customQuoting) { | ||
case GraveAccents: | ||
return '`' + std::regex_replace(id, std::regex("\\`"), "``") + '`'; | ||
case SquareBrackets: | ||
// There aren't any escaping possibilities for square brackets inside the identifier, | ||
// so we rely on the user to not enter these characters when this kind of quoting is | ||
// selected. | ||
return '[' + id + ']'; | ||
case DoubleQuotes: | ||
default: | ||
// This may produce a 'control reaches end of non-void function' warning if the | ||
// default branch is removed, even though we have covered all possibilities in the | ||
// switch statement. | ||
return '"' + std::regex_replace(id, std::regex("\\\""), "\"\"") + '"'; | ||
} | ||
} | ||
|
||
bool ObjectIdentifier::fromSerialised(const std::string& serialised) | ||
{ | ||
auto pos_comma = serialised.find(","); | ||
auto pos_colon = serialised.find(":"); | ||
if(pos_comma == serialised.npos || pos_colon == serialised.npos) | ||
return false; | ||
|
||
size_t size_schema, size_name; | ||
size_schema = std::stoul(serialised.substr(0, pos_comma)); | ||
size_name = std::stoul(serialised.substr(pos_comma+1, pos_colon-pos_comma)); | ||
if(pos_colon + size_schema + size_name + 1 != serialised.size()) | ||
return false; | ||
|
||
m_schema = serialised.substr(pos_colon + 1, size_schema); | ||
m_name = serialised.substr(pos_colon + size_schema + 1, size_name); | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#ifndef OBJECTIDENTIFIER_H | ||
#define OBJECTIDENTIFIER_H | ||
|
||
#include <string> | ||
|
||
namespace sqlb { | ||
|
||
enum escapeQuoting { | ||
DoubleQuotes, | ||
GraveAccents, | ||
SquareBrackets | ||
}; | ||
|
||
// Set quoting style for escapeIdentifier | ||
void setIdentifierQuoting(escapeQuoting toQuoting); | ||
|
||
// Add quotes to an identifier | ||
std::string escapeIdentifier(const std::string& id); | ||
|
||
// Object identifier consisting of schema name and object name | ||
class ObjectIdentifier | ||
{ | ||
public: | ||
ObjectIdentifier(const std::string& schema, const std::string& name) | ||
: m_schema(schema), | ||
m_name(name) | ||
{ | ||
} | ||
|
||
ObjectIdentifier() | ||
: m_schema("main") | ||
{ | ||
} | ||
|
||
explicit ObjectIdentifier(const std::string& variant) | ||
{ | ||
// Try to unserialise the parameter first. If that does not work, just assume it's an object name for the main schema | ||
clear(); | ||
if(!fromSerialised(variant)) | ||
m_name = variant; | ||
} | ||
|
||
bool operator==(const ObjectIdentifier& rhs) const | ||
{ | ||
return (rhs.m_schema == m_schema && rhs.m_name == m_name); | ||
} | ||
|
||
bool operator<(const ObjectIdentifier& rhs) const | ||
{ | ||
return toDisplayString() < rhs.toDisplayString(); | ||
} | ||
|
||
const std::string& schema() const { return m_schema; } | ||
const std::string& name() const { return m_name; } | ||
void setSchema(const std::string& schema) { m_schema = schema; } | ||
void setName(const std::string& name) { m_name = name; } | ||
|
||
void clear() | ||
{ | ||
m_schema = "main"; | ||
m_name.clear(); | ||
} | ||
|
||
bool isEmpty() const { return m_name.empty(); } | ||
|
||
// This returns a string which can be used in SQL statements | ||
std::string toString(bool shortName = false) const | ||
{ | ||
if(shortName && m_schema == "main") | ||
return sqlb::escapeIdentifier(m_name); | ||
else | ||
return sqlb::escapeIdentifier(m_schema) + "." + sqlb::escapeIdentifier(m_name); | ||
} | ||
|
||
// This returns a string which can be used in the user interface | ||
std::string toDisplayString() const | ||
{ | ||
if(m_schema == "main") | ||
return m_name; | ||
else | ||
return m_schema + "." + m_name; | ||
} | ||
|
||
std::string toSerialised() const | ||
{ | ||
return std::to_string(m_schema.size()) + "," + std::to_string(m_name.size()) + ":" + m_schema + m_name; | ||
} | ||
|
||
bool fromSerialised(const std::string& serialised); | ||
|
||
private: | ||
std::string m_schema; | ||
std::string m_name; | ||
}; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.