Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sleuthkit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IRT
Sleuthkit
Commits
f76ace0e
Commit
f76ace0e
authored
6 years ago
by
Raman
Browse files
Options
Downloads
Patches
Plain Diff
1171: Create IG table schema versions
parent
493cf4e7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java
+77
-1
77 additions, 1 deletion
...java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java
with
77 additions
and
1 deletion
bindings/java/src/org/sleuthkit/datamodel/CaseDbAccessManager.java
+
77
−
1
View file @
f76ace0e
/*
* Sleuth Kit Data Model
*
* Copyright 2018 Basis Technology Corp.
* Copyright 2018
-2019
Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
...
...
@@ -68,6 +68,51 @@ public interface CaseDbAccessQueryCallback {
this
.
tskDB
=
skCase
;
}
/**
* Checks if a column exists in a table.
*
* @param tableName name of the table
* @param columnName column name to check
*
* @return true if the column already exists, false otherwise
* @throws TskCoreException
*/
public
boolean
doesColumnExist
(
String
tableName
,
String
columnName
)
throws
TskCoreException
{
boolean
columnExists
=
false
;
Statement
statement
=
null
;
CaseDbConnection
connection
=
tskDB
.
getConnection
();
try
{
statement
=
connection
.
createStatement
();
if
(
DbType
.
SQLITE
==
tskDB
.
getDatabaseType
())
{
String
tableInfoQuery
=
"PRAGMA table_info(%s)"
;
//NON-NLS
ResultSet
resultSet
=
statement
.
executeQuery
(
String
.
format
(
tableInfoQuery
,
tableName
));
while
(
resultSet
.
next
())
{
// the second value is the column name
if
(
resultSet
.
getString
(
2
).
equals
(
columnName
))
{
columnExists
=
true
;
break
;
}
}
resultSet
.
close
();
}
else
{
String
tableInfoQueryTemplate
=
"SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='%s' AND column_name='%s')"
;
//NON-NLS
ResultSet
resultSet
=
statement
.
executeQuery
(
String
.
format
(
tableInfoQueryTemplate
,
tableName
.
toLowerCase
(),
columnName
.
toLowerCase
()));
if
(
resultSet
.
next
())
{
columnExists
=
resultSet
.
getBoolean
(
1
);
}
}
}
catch
(
SQLException
ex
)
{
throw
new
TskCoreException
(
"Error checking if column "
+
columnName
+
"exists "
,
ex
);
}
finally
{
closeStatement
(
statement
);
connection
.
close
();
}
return
columnExists
;
}
/**
* Creates a table with the specified name and schema.
*
...
...
@@ -104,6 +149,37 @@ public void createTable(final String tableName, final String tableSchema) throws
}
/**
* Alters a table with the specified name.
*
* @param tableName name of the table to alter
* @param alterSQL SQL to alter the table
*
* @throws TskCoreException
*/
public
void
alterTable
(
final
String
tableName
,
final
String
alterSQL
)
throws
TskCoreException
{
validateTableName
(
tableName
);
validateSQL
(
alterSQL
);
CaseDbConnection
connection
=
tskDB
.
getConnection
();
tskDB
.
acquireSingleUserCaseWriteLock
();
Statement
statement
=
null
;
String
sql
=
"ALTER TABLE "
+
tableName
+
" "
+
alterSQL
;
try
{
statement
=
connection
.
createStatement
();
statement
.
execute
(
sql
);
}
catch
(
SQLException
ex
)
{
throw
new
TskCoreException
(
String
.
format
(
"Error altering table %s with SQL = %s"
,
tableName
,
sql
),
ex
);
}
finally
{
closeStatement
(
statement
);
connection
.
close
();
tskDB
.
releaseSingleUserCaseWriteLock
();
}
}
/**
* Creates an index on the specified table, on specified column(s).
*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment