Evaluate row before inserting new row

I’m using the following to successfully insert a row in a database at the click of a button. (The filename and title are bookmark data. The title will appear on a bookmark button on a page showing all the app’s bookmarks, and the button will take you to the filename’s page. A Remove button at right will delete the row’s data.):

function insertRow() {
db = window.openDatabase("Database", "1.0", "BOOKMARKS4", 200000);
db.transaction(function(tx) {
	var id = document.title, filename = window.location.pathname, title = document.title;
	tx.executeSql("insert into BOOKMARKS4(id, filename, title) values(?,?,?)", [id, filename, title]);
	}, errorCB, successCB()); alert('Bookmark added.');
}

However, I want to make sure the same filename and title data is not inserted again and again, which is occurring now. I’d like an alert to show up declaring that the page has already been bookmarked.

The following alteration did not work (actually it prevented the insertRow function from working):

function insertRow() {
db = window.openDatabase("Database", "1.0", "BOOKMARKS4", 200000);
var filename;
if (filename.length > 1) {alert('You have already bookmarked this page'); return;}
else {
db.transaction(function(tx) {
	var id = document.title, filename = window.location.pathname, title = document.title;
	tx.executeSql("INSERT into BOOKMARKS4(id, filename, title) VALUES(?,?,?)", [id, filename, title]);
	}, errorCB, successCB()); alert('Bookmark added.');
	}
}

What’s the correct way to evaluate whether a cell is already populated, and execute on that basis?

Frankly, I don’t know if this is even possible.