add method to record file language

This commit is contained in:
mlangkabel
2018-12-12 15:38:49 +01:00
parent 20b2db0571
commit cba4e7318f
9 changed files with 77 additions and 21 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ cmake_minimum_required (VERSION 2.6)
set(TEST_CORE "test_core")
set(INTERFACE_VERSION 0)
set(DATABASE_VERSION 22)
set(DATABASE_VERSION 23)
set(COMMIT_VERSION 1)
set(VERSION_STRING "v${INTERFACE_VERSION}_db${DATABASE_VERSION}_c${COMMIT_VERSION}")
+1
View File
@@ -69,6 +69,7 @@ namespace sourcetrail
int addError(const StorageErrorData& storageErrorData);
void setNodeType(int nodeId, int nodeKind);
void setFileLanguage(int fileId, const std::string& languageIdentifier);
template <typename ResultType>
std::vector<ResultType> getAll() const
+1
View File
@@ -78,6 +78,7 @@ namespace sourcetrail
bool recordReferenceLocation(int referenceId, const SourceRange& location);
int recordFile(const std::string& filePath);
bool recordFileLanguage(int fileId, const std::string& languageIdentifier);
int recordLocalSymbol(const std::string& name);
bool recordLocalSymbolLocation(int localSymbolId, const SourceRange& location);
+4 -9
View File
@@ -26,22 +26,16 @@ namespace sourcetrail
StorageFile()
: id(0)
, filePath("")
, languageIdentifier("")
, modificationTime("")
, indexed(true)
, complete(true)
{}
StorageFile(int id, std::string filePath, bool indexed, bool complete)
: id(id)
, filePath(std::move(filePath))
, modificationTime("")
, indexed(indexed)
, complete(complete)
{}
StorageFile(int id, std::string filePath, std::string modificationTime, bool indexed, bool complete)
StorageFile(int id, std::string filePath, std::string languageIdentifier, std::string modificationTime, bool indexed, bool complete)
: id(id)
, filePath(std::move(filePath))
, languageIdentifier(std::move(languageIdentifier))
, modificationTime(std::move(modificationTime))
, indexed(indexed)
, complete(complete)
@@ -49,6 +43,7 @@ namespace sourcetrail
int id;
std::string filePath;
std::string languageIdentifier;
std::string modificationTime;
bool indexed;
bool complete;
+23 -10
View File
@@ -116,6 +116,7 @@ namespace sourcetrail
"CREATE TABLE IF NOT EXISTS file("
" id INTEGER NOT NULL, "
" path TEXT, "
" language TEXT, "
" modification_time TEXT, "
" indexed INTEGER, "
" complete INTEGER, "
@@ -352,14 +353,15 @@ namespace sourcetrail
{
CppSQLite3Statement stmt = m_database.compileStatement(
"INSERT OR IGNORE INTO file(id, path, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?);"
"INSERT OR IGNORE INTO file(id, path, language, modification_time, indexed, complete, line_count) VALUES(?, ?, ?, ?, ?, ?, ?);"
);
stmt.bind(1, storageFile.id);
stmt.bind(2, storageFile.filePath.c_str());
stmt.bind(3, storageFile.modificationTime.c_str());
stmt.bind(4, storageFile.indexed);
stmt.bind(5, storageFile.complete);
stmt.bind(6, lineCount);
stmt.bind(3, storageFile.languageIdentifier.c_str());
stmt.bind(4, storageFile.modificationTime.c_str());
stmt.bind(5, storageFile.indexed);
stmt.bind(6, storageFile.complete);
stmt.bind(7, lineCount);
executeStatement(stmt);
}
@@ -561,6 +563,16 @@ namespace sourcetrail
executeStatement(stmt);
}
void DatabaseStorage::setFileLanguage(int fileId, const std::string& languageIdentifier)
{
CppSQLite3Statement stmt = m_database.compileStatement(
"UPDATE file SET language = ? WHERE id == ?;"
);
stmt.bind(1, languageIdentifier.c_str());
stmt.bind(2, fileId);
executeStatement(stmt);
}
// --- Private Interface ---
void DatabaseStorage::insertOrUpdateMetaValue(const std::string& key, const std::string& value)
@@ -701,7 +713,7 @@ namespace sourcetrail
std::vector<StorageFile> DatabaseStorage::doGetAll<StorageFile>(const std::string& query) const
{
CppSQLite3Query q = executeQuery(
"SELECT id, path, modification_time, indexed, complete FROM file " + query + ";"
"SELECT id, path, language, modification_time, indexed, complete FROM file " + query + ";"
);
std::vector<StorageFile> files;
@@ -709,13 +721,14 @@ namespace sourcetrail
{
const int id = q.getIntField(0, 0);
const std::string filePath = q.getStringField(1, "");
const std::string modificationTime = q.getStringField(2, "");
const bool indexed = q.getIntField(3, 0);
const bool complete = q.getIntField(4, 0);
const std::string languageIdentifier = q.getStringField(2, "");
const std::string modificationTime = q.getStringField(3, "");
const bool indexed = q.getIntField(4, 0);
const bool complete = q.getIntField(5, 0);
if (id != 0)
{
files.emplace_back(StorageFile(id, filePath, modificationTime, indexed, complete));
files.emplace_back(StorageFile(id, filePath, languageIdentifier, modificationTime, indexed, complete));
}
q.nextRow();
}
+22 -1
View File
@@ -480,6 +480,27 @@ namespace sourcetrail
}
}
bool SourcetrailDBWriter::recordFileLanguage(int fileId, const std::string& languageIdentifier)
{
if (!m_storage)
{
m_lastError = "Unable to record file language, because no database is currently open.";
return false;
}
try
{
m_storage->setFileLanguage(fileId, languageIdentifier);
}
catch (const SourcetrailException e)
{
m_lastError = e.getMessage();
return false;
}
return true;
}
int SourcetrailDBWriter::recordLocalSymbol(const std::string& name)
{
if (!m_storage)
@@ -678,7 +699,7 @@ namespace sourcetrail
const int nodeId = addNodeHierarchy(nameHierarchy);
m_storage->setNodeType(nodeId, nodeKindToInt(NODE_FILE));
m_storage->addFile(StorageFile(nodeId, filePath, utility::getDateTimeString(time(0)), true, true));
m_storage->addFile(StorageFile(nodeId, filePath, "", utility::getDateTimeString(time(0)), true, true));
return nodeId;
}
+18
View File
@@ -300,6 +300,7 @@ namespace sourcetrail
REQUIRE(files.size() == 1);
REQUIRE(files.front().id == idFile1);
REQUIRE(files.front().filePath == filePath);
REQUIRE(files.front().languageIdentifier == "");
}
SECTION("writer does not record file twice")
@@ -312,6 +313,23 @@ namespace sourcetrail
REQUIRE(files.size() == 1);
}
SECTION("writer records file language")
{
const std::string languageIdentifier = "testlanguage";
const bool success = writer.recordFileLanguage(
idFile1,
languageIdentifier
);
REQUIRE(success);
REQUIRE(writer.getLastError() == "");
const std::vector<StorageFile> files = storage->getAll<StorageFile>();
REQUIRE(files.size() == 1);
REQUIRE(files.front().id == idFile1);
REQUIRE(files.front().languageIdentifier == languageIdentifier);
}
writer.close();
REQUIRE(writer.getLastError() == "");
}
+2
View File
@@ -95,6 +95,8 @@ bool recordReferenceLocation(int referenceId, std::string filePath, int startLin
int recordFile(std::string filePath);
bool recordFileLanguage(int fileId, std::string languageIdentifier);
int recordLocalSymbol(std::string name);
bool recordLocalSymbolLocation(int localSymbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
+5
View File
@@ -191,6 +191,11 @@ int recordFile(std::string filePath)
return dbWriter.recordFile(filePath);
}
bool recordFileLanguage(int fileId, std::string languageIdentifier)
{
return dbWriter.recordFileLanguage(fileId, languageIdentifier);
}
int recordLocalSymbol(std::string name)
{
return dbWriter.recordLocalSymbol(name);