Skip to content

Commit

Permalink
#169: fixed csv import under ao10: now updating both databases works …
Browse files Browse the repository at this point in the history
…as expected
  • Loading branch information
k3b committed Feb 7, 2021
1 parent 8e1f533 commit 7f90ca6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@

import de.k3b.android.androFotoFinder.Global;
import de.k3b.android.androFotoFinder.R;
import de.k3b.android.androFotoFinder.queries.FotoSql;
import de.k3b.android.androFotoFinder.tagDB.TagSql;
import de.k3b.android.io.AndroidFileCommands;
import de.k3b.android.util.IntentUtil;
import de.k3b.csv2db.csv.CsvLoader;
import de.k3b.io.FileUtils;
import de.k3b.io.VISIBILITY;
import de.k3b.io.filefacade.FileFacade;
import de.k3b.io.filefacade.IFile;
import de.k3b.media.PhotoPropertiesCsvItem;
Expand Down Expand Up @@ -206,7 +206,9 @@ private void updateDB(String dbgContext, String _path, long xmlLastFileModifyDat

TagSql.setFileModifyDate(dbValues, new Date());

mUpdateCount += TagSql.execUpdate(dbgContext, path, xmlLastFileModifyDate, dbValues, VISIBILITY.PRIVATE_PUBLIC);
dbValues.put(FotoSql.SQL_COL_PATH, path);
mUpdateCount += TagSql.insertOrUpdateMediaDatabaseFromCsv(
dbgContext, path, xmlLastFileModifyDate, dbValues, null);
mItemCount++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int execUpdate(String dbgContext, long id, ContentValues values) {
dbgContext += " " + id + " not found or no change in contentprovider.";

String path = values.getAsString(FotoSql.SQL_COL_PATH);
Long changedId = FotoSql.getId(dbgContext, getWriteChild(), path);
Long changedId = FotoSql.getId(dbgContext, contentProvider, path);
if (changedId != null && id != changedId.longValue()) {
// pk in contentprovidser has changed
dbgContext += " unsing " + path + "(" + changedId + ") instead";
Expand All @@ -66,7 +66,8 @@ public int execUpdate(String dbgContext, long id, ContentValues values) {

@Override
public int execUpdate(String dbgContext, String path, ContentValues values, VISIBILITY visibility) {
int result = super.execUpdate(dbgContext, path, values, visibility);
int result = super.execUpdate(
dbgContext, path, values, visibility);
database.execUpdate(dbgContext, path, values, visibility);
return result;
}
Expand All @@ -91,7 +92,7 @@ public int exexUpdateImpl(String dbgContext, ContentValues values, String sqlWhe
public Long insertOrUpdateMediaDatabase(String dbgContext, String dbUpdateFilterJpgFullPathName,
ContentValues values, VISIBILITY visibility, Long updateSuccessValue) {
Long result = updateSuccessValue;

Uri uriWithId = null;
int modifyCount = contentProvider.execUpdate(dbgContext, dbUpdateFilterJpgFullPathName,
values, visibility);

Expand All @@ -100,13 +101,28 @@ public Long insertOrUpdateMediaDatabase(String dbgContext, String dbUpdateFilter
FotoSql.addDateAdded(values);

// insert into contentProvider and database
Uri uriWithId = execInsert(dbgContext, values);
result = FotoSql.getId(uriWithId);
} else {
// update into contentprovider successfull. also add to database
database.execUpdate(dbgContext, dbUpdateFilterJpgFullPathName,
values, visibility);
uriWithId = contentProvider.execInsert(dbgContext, values);

if (uriWithId != null) {
result = FotoSql.getId(uriWithId);
values.put(FotoSql.SQL_COL_PK, result);
}
}

modifyCount = database.execUpdate(dbgContext, dbUpdateFilterJpgFullPathName,
values, visibility);

if (modifyCount == 0) {
// update failed (probably becauce oldFullPathName not found. try insert it.
FotoSql.addDateAdded(values);

// insert into contentProvider and database
uriWithId = database.execInsert(dbgContext, values);
if (uriWithId != null) {
result = FotoSql.getId(uriWithId);
}
}

return result;
}

Expand All @@ -125,7 +141,7 @@ public Uri execInsert(String dbgContext, ContentValues values) {
// not inserted because in android-contentprovider may already exist.
// get id from android-contentprovider
String path = values.getAsString(FotoSql.SQL_COL_PATH);
Long id = FotoSql.getId(dbgContext, getWriteChild(), path);
Long id = FotoSql.getId(dbgContext, contentProvider, path);

if (id == null) {
Log.i(LOG_TAG, dbgContext + " Path '" + path + "' not found. Aborted.");
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/de/k3b/android/androFotoFinder/tagDB/TagSql.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,10 @@ public static void setFileModifyDate(ContentValues values, long fileModifyDateSe
* @param allowSetNulls if one of these columns are null, the set null is copied, too
* @return number of changed db items
*/
public static int updateDB(String dbgContext, String oldFullJpgFilePath,
PhotoPropertiesUpdateHandler jpg, MediaFormatter.FieldID... allowSetNulls) {
public static Long updateDB(
String dbgContext, String oldFullJpgFilePath,
PhotoPropertiesUpdateHandler jpg,
MediaFormatter.FieldID... allowSetNulls) {
if ((jpg != null) && (!PhotoPropertiesMediaFilesScanner.isNoMedia(oldFullJpgFilePath))) {
ContentValues dbValues = new ContentValues();
PhotoPropertiesMediaDBContentValues mediaValueAdapter = new PhotoPropertiesMediaDBContentValues();
Expand All @@ -372,21 +374,23 @@ public static int updateDB(String dbgContext, String oldFullJpgFilePath,
TagSql.setXmpFileModifyDate(dbValues, xmpFilelastModified);
TagSql.setFileModifyDate(dbValues, newFullJpgFilePath);

return TagSql.execUpdate(dbgContext, oldFullJpgFilePath,
TagSql.EXT_LAST_EXT_SCAN_UNKNOWN, dbValues, VISIBILITY.PRIVATE_PUBLIC);
return TagSql.insertOrUpdateMediaDatabaseFromCsv(
dbgContext, oldFullJpgFilePath,
TagSql.EXT_LAST_EXT_SCAN_UNKNOWN,
dbValues, VISIBILITY.PRIVATE_PUBLIC);
}


}
return 0;
return 0L;
}


public static int execUpdate(String dbgContext, String path, long xmpFileDate, ContentValues values, VISIBILITY visibility) {
if (!Global.Media.enableXmpNone || isPseudoXmpFileDateVauel(xmpFileDate)) {
return getMediaDBApi().execUpdate(dbgContext, path, values, visibility);
}
return getMediaDBApi().exexUpdateImpl(dbgContext, values, FILTER_EXPR_PATH_AND_XMP_DATE_LESS_THAN, new String[]{path, Long.toString(xmpFileDate)});
public static Long insertOrUpdateMediaDatabaseFromCsv(
String dbgContext, String path, long xmpFileDate,
ContentValues values, VISIBILITY visibility) {
return getMediaDBApi().insertOrUpdateMediaDatabase(
dbgContext, path, values, visibility,1L);
}

public static List<String> getPhotosNeverScanned(String path) {
Expand Down

0 comments on commit 7f90ca6

Please sign in to comment.