Changed translators.type column to INT and added index

Updated scraper updated mechanism to handle new translator schema, roughly
This commit is contained in:
Dan Stillman 2006-06-29 07:58:50 +00:00
parent 7328a3eab3
commit 6c88563ded
2 changed files with 21 additions and 14 deletions

View File

@ -289,7 +289,7 @@ Scholar.Schema = new function(){
var currentTime = xmlhttp.responseXML. var currentTime = xmlhttp.responseXML.
getElementsByTagName('currentTime')[0].firstChild.nodeValue; getElementsByTagName('currentTime')[0].firstChild.nodeValue;
var updates = xmlhttp.responseXML.getElementsByTagName('scraper'); var updates = xmlhttp.responseXML.getElementsByTagName('translator');
Scholar.DB.beginTransaction(); Scholar.DB.beginTransaction();
@ -361,19 +361,24 @@ Scholar.Schema = new function(){
function _scraperXMLToDBQuery(xmlnode){ function _scraperXMLToDBQuery(xmlnode){
var sqlValues = [ var sqlValues = [
{'string':xmlnode.getAttribute('id')}, {'string':xmlnode.getAttribute('id')},
{'string':centralLastUpdated = xmlnode.getAttribute('lastUpdated')}, {'string':xmlnode.getAttribute('lastUpdated')},
{'string':xmlnode.getAttribute('type')},
{'string':xmlnode.getElementsByTagName('label')[0].firstChild.nodeValue}, {'string':xmlnode.getElementsByTagName('label')[0].firstChild.nodeValue},
{'string':xmlnode.getElementsByTagName('creator')[0].firstChild.nodeValue}, {'string':xmlnode.getElementsByTagName('creator')[0].firstChild.nodeValue},
{'string':xmlnode.getElementsByTagName('urlPattern')[0].firstChild.nodeValue}, // target
// scraperDetectCode can not exist or be empty (xmlnode.getElementsByTagName('target').item(0) &&
(xmlnode.getElementsByTagName('scraperDetectCode').item(0) && xmlnode.getElementsByTagName('target')[0].firstChild)
xmlnode.getElementsByTagName('scraperDetectCode')[0].firstChild) ? {'string':xmlnode.getElementsByTagName('target')[0].firstChild.nodeValue}
? {'string':xmlnode.getElementsByTagName('scraperDetectCode')[0].firstChild.nodeValue}
: {'null':true}, : {'null':true},
{'string':xmlnode.getElementsByTagName('scraperJavaScript')[0].firstChild.nodeValue} // detectCode can not exist or be empty
(xmlnode.getElementsByTagName('detectCode').item(0) &&
xmlnode.getElementsByTagName('detectCode')[0].firstChild)
? {'string':xmlnode.getElementsByTagName('detectCode')[0].firstChild.nodeValue}
: {'null':true},
{'string':xmlnode.getElementsByTagName('code')[0].firstChild.nodeValue}
] ]
var sql = "REPLACE INTO scrapers VALUES (?,?,?,?,?,?,?)"; var sql = "REPLACE INTO translators VALUES (?,?,?,?,?,?,?,?)";
return Scholar.DB.query(sql, sqlValues); return Scholar.DB.query(sql, sqlValues);
} }
@ -385,7 +390,7 @@ Scholar.Schema = new function(){
// //
// Change this value to match the schema version // Change this value to match the schema version
// //
var toVersion = 28; var toVersion = 29;
if (toVersion != _getSchemaSQLVersion()){ if (toVersion != _getSchemaSQLVersion()){
throw('Schema version does not match version in _migrateSchema()'); throw('Schema version does not match version in _migrateSchema()');
@ -399,8 +404,8 @@ Scholar.Schema = new function(){
// //
// Each block performs the changes necessary to move from the // Each block performs the changes necessary to move from the
// previous revision to that one. // previous revision to that one.
for (var i=parseInt(fromVersion) + 1; i<=toVersion; i++){ for (var i=fromVersion + 1; i<=toVersion; i++){
if (i==28){ if (i==29){
Scholar.DB.query("DROP TABLE IF EXISTS keywords"); Scholar.DB.query("DROP TABLE IF EXISTS keywords");
Scholar.DB.query("DROP TABLE IF EXISTS itemKeywords"); Scholar.DB.query("DROP TABLE IF EXISTS itemKeywords");
Scholar.DB.query("DROP TABLE IF EXISTS scrapers"); Scholar.DB.query("DROP TABLE IF EXISTS scrapers");

View File

@ -1,4 +1,4 @@
-- 28 -- 29
DROP TABLE IF EXISTS version; DROP TABLE IF EXISTS version;
CREATE TABLE version ( CREATE TABLE version (
@ -151,13 +151,15 @@
CREATE TABLE translators ( CREATE TABLE translators (
translatorID TEXT PRIMARY KEY, translatorID TEXT PRIMARY KEY,
lastUpdated DATETIME, lastUpdated DATETIME,
type TEXT, type INT,
label TEXT, label TEXT,
creator TEXT, creator TEXT,
target TEXT, target TEXT,
detectCode TEXT, detectCode TEXT,
code TEXT code TEXT
); );
DROP INDEX IF EXISTS translators_type;
CREATE INDEX translators_type ON translators(type);
DROP TABLE IF EXISTS transactionSets; DROP TABLE IF EXISTS transactionSets;
CREATE TABLE transactionSets ( CREATE TABLE transactionSets (