307 SleuthkitCase newCase = SleuthkitCase.newCase(icd.getPostgreSQLDbName(), icd.getDb(), icd.getCaseOutputFolder().toString());
311 Class.forName(
"org.sqlite.JDBC");
316 Statement inputStatement = sqliteConnection.createStatement();
317 ResultSet inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_types");
318 Statement outputStatement;
319 Statement numberingPK;
322 while (inputResultSet.next()) {
324 long value = inputResultSet.getLong(1);
325 if (value > biggestPK) {
328 Statement check = postgreSQLConnection.createStatement();
329 ResultSet checkResult = check.executeQuery(
"SELECT * FROM blackboard_artifact_types WHERE artifact_type_id=" + value +
" AND type_name LIKE '" + inputResultSet.getString(2) +
"' AND display_name LIKE '" + inputResultSet.getString(3) +
"'");
330 if (!checkResult.isBeforeFirst()) {
331 String sql =
"INSERT INTO blackboard_artifact_types (artifact_type_id, type_name, display_name) VALUES ("
333 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
335 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
339 }
catch (SQLException ex) {
340 if (ex.getErrorCode() != 0) {
341 throw new SQLException(ex);
345 numberingPK = postgreSQLConnection.createStatement();
346 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_types_artifact_type_id_seq RESTART WITH " + (biggestPK + 1));
350 inputStatement = sqliteConnection.createStatement();
351 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attribute_types");
353 while (inputResultSet.next()) {
355 long value = inputResultSet.getLong(1);
356 if (value > biggestPK) {
359 Statement check = postgreSQLConnection.createStatement();
360 ResultSet checkResult = check.executeQuery(
"SELECT * FROM blackboard_attribute_types WHERE attribute_type_id=" + value +
" AND type_name LIKE '" + inputResultSet.getString(2) +
"' AND display_name LIKE '" + inputResultSet.getString(3) +
"'");
361 if (!checkResult.isBeforeFirst()) {
362 String sql =
"INSERT INTO blackboard_attribute_types (attribute_type_id, type_name, display_name) VALUES ("
364 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
367 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
371 }
catch (SQLException ex) {
372 if (ex.getErrorCode() != 0) {
373 throw new SQLException(ex);
377 numberingPK = postgreSQLConnection.createStatement();
378 numberingPK.execute(
"ALTER SEQUENCE blackboard_attribute_types_attribute_type_id_seq RESTART WITH " + (biggestPK + 1));
382 inputStatement = sqliteConnection.createStatement();
383 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_objects");
385 while (inputResultSet.next()) {
386 outputStatement = postgreSQLConnection.createStatement();
388 long value = inputResultSet.getLong(1);
389 if (value > biggestPK) {
392 outputStatement.executeUpdate(
"INSERT INTO tsk_objects (obj_id, par_obj_id, type) VALUES ("
395 + inputResultSet.getInt(3) +
")");
396 }
catch (SQLException ex) {
397 if (ex.getErrorCode() != 0) {
398 throw new SQLException(ex);
402 numberingPK = postgreSQLConnection.createStatement();
403 numberingPK.execute(
"ALTER SEQUENCE tsk_objects_obj_id_seq RESTART WITH " + (biggestPK + 1));
406 inputStatement = sqliteConnection.createStatement();
407 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_names");
409 while (inputResultSet.next()) {
410 outputStatement = postgreSQLConnection.createStatement();
412 outputStatement.executeUpdate(
"INSERT INTO tsk_image_names (obj_id, name, sequence) VALUES ("
413 + inputResultSet.getLong(1) +
",'"
414 + inputResultSet.getString(2) +
"',"
415 + inputResultSet.getInt(3) +
")");
416 }
catch (SQLException ex) {
417 if (ex.getErrorCode() != 0) {
418 throw new SQLException(ex);
425 inputStatement = sqliteConnection.createStatement();
426 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_image_info");
428 while (inputResultSet.next()) {
430 long value = inputResultSet.getLong(1);
431 if (value > biggestPK) {
434 String sql =
"INSERT INTO tsk_image_info (obj_id, type, ssize, tzone, size, md5, display_name) VALUES ("
443 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
449 }
catch (SQLException ex) {
450 if (ex.getErrorCode() != 0) {
451 throw new SQLException(ex);
455 numberingPK = postgreSQLConnection.createStatement();
456 numberingPK.execute(
"ALTER SEQUENCE tsk_image_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
460 inputStatement = sqliteConnection.createStatement();
461 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_fs_info");
463 while (inputResultSet.next()) {
465 long value = inputResultSet.getLong(1);
466 if (value > biggestPK) {
469 String sql =
"INSERT INTO tsk_fs_info (obj_id, img_offset, fs_type, block_size, block_count, root_inum, first_inum, last_inum, display_name) VALUES ("
471 + inputResultSet.getLong(2) +
","
472 + inputResultSet.getInt(3) +
","
473 + inputResultSet.getLong(4) +
","
474 + inputResultSet.getLong(5) +
","
475 + inputResultSet.getLong(6) +
","
476 + inputResultSet.getLong(7) +
","
477 + inputResultSet.getLong(8) +
","
480 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
484 }
catch (SQLException ex) {
485 if (ex.getErrorCode() != 0) {
486 throw new SQLException(ex);
490 numberingPK = postgreSQLConnection.createStatement();
491 numberingPK.execute(
"ALTER SEQUENCE tsk_fs_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
495 inputStatement = sqliteConnection.createStatement();
496 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_path");
498 while (inputResultSet.next()) {
499 outputStatement = postgreSQLConnection.createStatement();
501 long value = inputResultSet.getLong(1);
502 if (value > biggestPK) {
508 int encoding = TskData.EncodingType.NONE.getType();
509 ResultSetMetaData rsMetaData = inputResultSet.getMetaData();
510 if (rsMetaData.getColumnCount() == 3) {
511 encoding = inputResultSet.getInt(3);
513 outputStatement.executeUpdate(
"INSERT INTO tsk_files_path (obj_id, path, encoding_type) VALUES ("
515 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"', "
517 }
catch (SQLException ex) {
518 if (ex.getErrorCode() != 0) {
519 throw new SQLException(ex);
523 numberingPK = postgreSQLConnection.createStatement();
524 numberingPK.execute(
"ALTER SEQUENCE tsk_files_path_obj_id_seq RESTART WITH " + (biggestPK + 1));
528 inputStatement = sqliteConnection.createStatement();
529 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files");
531 while (inputResultSet.next()) {
533 long value = inputResultSet.getLong(1);
534 if (value > biggestPK) {
537 String sql =
"INSERT INTO tsk_files (obj_id, fs_obj_id, attr_type, attr_id, name, meta_addr, meta_seq, type, has_layout, has_path, dir_type, meta_type, dir_flags, meta_flags, size, ctime, crtime, atime, mtime, mode, uid, gid, md5, known, parent_path) VALUES ("
542 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) +
"',"
564 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
569 }
catch (SQLException ex) {
570 if (ex.getErrorCode() != 0) {
571 throw new SQLException(ex);
575 numberingPK = postgreSQLConnection.createStatement();
576 numberingPK.execute(
"ALTER SEQUENCE tsk_files_obj_id_seq RESTART WITH " + (biggestPK + 1));
579 inputStatement = sqliteConnection.createStatement();
580 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_file_layout");
582 while (inputResultSet.next()) {
583 outputStatement = postgreSQLConnection.createStatement();
585 outputStatement.executeUpdate(
"INSERT INTO tsk_file_layout (obj_id, byte_start, byte_len, sequence) VALUES ("
586 + inputResultSet.getLong(1) +
","
587 + inputResultSet.getLong(2) +
","
588 + inputResultSet.getLong(3) +
","
589 + inputResultSet.getInt(4) +
")");
590 }
catch (SQLException ex) {
591 if (ex.getErrorCode() != 0) {
592 throw new SQLException(ex);
598 inputStatement = sqliteConnection.createStatement();
599 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_db_info");
601 while (inputResultSet.next()) {
602 outputStatement = postgreSQLConnection.createStatement();
604 Statement check = postgreSQLConnection.createStatement();
605 ResultSet checkResult = check.executeQuery(
"SELECT * FROM tsk_db_info WHERE schema_ver=" + inputResultSet.getInt(1) +
" AND tsk_ver=" + inputResultSet.getInt(2));
606 if (!checkResult.isBeforeFirst()) {
607 outputStatement.executeUpdate(
"INSERT INTO tsk_db_info (schema_ver, tsk_ver) VALUES ("
611 }
catch (SQLException ex) {
612 if (ex.getErrorCode() != 0) {
613 throw new SQLException(ex);
620 inputStatement = sqliteConnection.createStatement();
621 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tag_names");
623 while (inputResultSet.next()) {
625 long value = inputResultSet.getLong(1);
626 if (value > biggestPK) {
629 String sql =
"INSERT INTO tag_names (tag_name_id, display_name, description, color) VALUES ("
632 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(3)) +
"','"
633 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) +
"')";
635 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
639 }
catch (SQLException ex) {
640 if (ex.getErrorCode() != 0) {
641 throw new SQLException(ex);
645 numberingPK = postgreSQLConnection.createStatement();
646 numberingPK.execute(
"ALTER SEQUENCE tag_names_tag_name_id_seq RESTART WITH " + (biggestPK + 1));
650 inputStatement = sqliteConnection.createStatement();
651 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM reports");
653 while (inputResultSet.next()) {
654 outputStatement = postgreSQLConnection.createStatement();
656 long value = inputResultSet.getLong(1);
657 if (value > biggestPK) {
660 outputStatement.executeUpdate(
"INSERT INTO reports (report_id, path, crtime, src_module_name, report_name) VALUES ("
662 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(2)) +
"',"
663 + inputResultSet.getInt(3) +
",'"
664 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(4)) +
"','"
665 + SleuthkitCase.escapeSingleQuotes(inputResultSet.getString(5)) +
"')");
667 }
catch (SQLException ex) {
668 if (ex.getErrorCode() != 0) {
669 throw new SQLException(ex);
673 numberingPK = postgreSQLConnection.createStatement();
674 numberingPK.execute(
"ALTER SEQUENCE reports_report_id_seq RESTART WITH " + (biggestPK + 1));
677 biggestPK = Long.MIN_VALUE;
678 inputStatement = sqliteConnection.createStatement();
679 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifacts");
681 while (inputResultSet.next()) {
682 outputStatement = postgreSQLConnection.createStatement();
684 long value = inputResultSet.getLong(1);
685 if (value > biggestPK) {
688 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifacts (artifact_id, obj_id, artifact_type_id) VALUES ("
690 + inputResultSet.getLong(2) +
","
691 + inputResultSet.getLong(3) +
")");
693 }
catch (SQLException ex) {
694 if (ex.getErrorCode() != 0) {
695 throw new SQLException(ex);
699 numberingPK = postgreSQLConnection.createStatement();
700 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifacts_artifact_id_seq RESTART WITH " + (biggestPK + 1));
703 inputStatement = sqliteConnection.createStatement();
704 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_attributes");
706 while (inputResultSet.next()) {
708 String sql =
"INSERT INTO blackboard_attributes (artifact_id, artifact_type_id, source, context, attribute_type_id, value_type, value_byte, value_text, value_int32, value_int64, value_double) VALUES ("
709 + inputResultSet.getLong(1) +
","
710 + inputResultSet.getLong(2) +
","
713 + inputResultSet.getLong(5) +
","
714 + inputResultSet.getInt(6) +
","
720 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
728 }
catch (SQLException ex) {
729 if (ex.getErrorCode() != 0) {
730 throw new SQLException(ex);
737 inputStatement = sqliteConnection.createStatement();
738 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_parts");
740 while (inputResultSet.next()) {
742 long value = inputResultSet.getLong(1);
743 if (value > biggestPK) {
746 String sql =
"INSERT INTO tsk_vs_parts (obj_id, addr, start, length, descr, flags) VALUES ("
748 + inputResultSet.getLong(2) +
","
749 + inputResultSet.getLong(3) +
","
750 + inputResultSet.getLong(4) +
","
752 + inputResultSet.getInt(6) +
")";
753 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
757 }
catch (SQLException ex) {
758 if (ex.getErrorCode() != 0) {
759 throw new SQLException(ex);
763 numberingPK = postgreSQLConnection.createStatement();
764 numberingPK.execute(
"ALTER SEQUENCE tsk_vs_parts_obj_id_seq RESTART WITH " + (biggestPK + 1));
768 inputStatement = sqliteConnection.createStatement();
769 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_vs_info");
771 while (inputResultSet.next()) {
772 outputStatement = postgreSQLConnection.createStatement();
774 long value = inputResultSet.getLong(1);
775 if (value > biggestPK) {
778 outputStatement.executeUpdate(
"INSERT INTO tsk_vs_info (obj_id, vs_type, img_offset, block_size) VALUES ("
780 + inputResultSet.getInt(2) +
","
781 + inputResultSet.getLong(3) +
","
782 + inputResultSet.getLong(4) +
")");
784 }
catch (SQLException ex) {
785 if (ex.getErrorCode() != 0) {
786 throw new SQLException(ex);
790 numberingPK = postgreSQLConnection.createStatement();
791 numberingPK.execute(
"ALTER SEQUENCE tsk_vs_info_obj_id_seq RESTART WITH " + (biggestPK + 1));
795 inputStatement = sqliteConnection.createStatement();
796 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived");
798 while (inputResultSet.next()) {
800 long value = inputResultSet.getLong(1);
801 if (value > biggestPK) {
804 String sql =
"INSERT INTO tsk_files_derived (obj_id, derived_id, rederive) VALUES ("
806 + inputResultSet.getLong(2) +
","
808 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
812 }
catch (SQLException ex) {
813 if (ex.getErrorCode() != 0) {
814 throw new SQLException(ex);
818 numberingPK = postgreSQLConnection.createStatement();
819 numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_obj_id_seq RESTART WITH " + (biggestPK + 1));
823 inputStatement = sqliteConnection.createStatement();
824 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM tsk_files_derived_method");
826 while (inputResultSet.next()) {
828 long value = inputResultSet.getLong(1);
829 if (value > biggestPK) {
832 String sql =
"INSERT INTO tsk_files_derived_method (derived_id, tool_name, tool_version, other) VALUES ("
834 + inputResultSet.getString(2) +
"','"
835 + inputResultSet.getString(3) +
"',"
837 PreparedStatement pst = postgreSQLConnection.prepareStatement(sql);
841 }
catch (SQLException ex) {
842 if (ex.getErrorCode() != 0) {
843 throw new SQLException(ex);
847 numberingPK = postgreSQLConnection.createStatement();
848 numberingPK.execute(
"ALTER SEQUENCE tsk_files_derived_method_derived_id_seq RESTART WITH " + (biggestPK + 1));
852 inputStatement = sqliteConnection.createStatement();
853 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM content_tags LEFT OUTER JOIN tsk_examiners ON content_tags.examiner_id = tsk_examiners.examiner_id");
855 while (inputResultSet.next()) {
856 outputStatement = postgreSQLConnection.createStatement();
858 long value = inputResultSet.getLong(1);
859 if (value > biggestPK) {
862 outputStatement.executeUpdate(
"INSERT INTO content_tags (tag_id, obj_id, tag_name_id, comment, begin_byte_offset, end_byte_offset, examiner_id) VALUES ("
864 + inputResultSet.getLong(2) +
","
865 + inputResultSet.getLong(3) +
",'"
866 + inputResultSet.getString(4) +
"',"
867 + inputResultSet.getLong(5) +
","
868 + inputResultSet.getLong(6) +
","
869 + inputResultSet.getInt(7) +
")");
871 }
catch (SQLException ex) {
872 if (ex.getErrorCode() != 0) {
873 throw new SQLException(ex);
877 numberingPK = postgreSQLConnection.createStatement();
878 numberingPK.execute(
"ALTER SEQUENCE content_tags_tag_id_seq RESTART WITH " + (biggestPK + 1));
882 inputStatement = sqliteConnection.createStatement();
883 inputResultSet = inputStatement.executeQuery(
"SELECT * FROM blackboard_artifact_tags");
885 while (inputResultSet.next()) {
886 outputStatement = postgreSQLConnection.createStatement();
888 long value = inputResultSet.getLong(1);
889 if (value > biggestPK) {
892 outputStatement.executeUpdate(
"INSERT INTO blackboard_artifact_tags (tag_id, artifact_id, tag_name_id, comment) VALUES ("
894 + inputResultSet.getLong(2) +
","
895 + inputResultSet.getLong(3) +
",'"
896 + inputResultSet.getString(4) +
"','"
897 + inputResultSet.getString(5) +
"')");
899 }
catch (SQLException ex) {
900 if (ex.getErrorCode() != 0) {
901 throw new SQLException(ex);
905 numberingPK = postgreSQLConnection.createStatement();
906 numberingPK.execute(
"ALTER SEQUENCE blackboard_artifact_tags_tag_id_seq RESTART WITH " + (biggestPK + 1));
908 sqliteConnection.close();
909 postgreSQLConnection.close();