From 1e6a704dd3bdce7b0d52728f5a1055ee2661e97f Mon Sep 17 00:00:00 2001 From: gtarasov Date: Thu, 11 Feb 2016 17:26:40 +0300 Subject: [PATCH 1/3] save sqlite db in the right folder --- -/db.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/-/db.php b/-/db.php index b21c9e3..23d9ac3 100755 --- a/-/db.php +++ b/-/db.php @@ -6,7 +6,7 @@ // connect try { if ( DB_DRIVER == 'sqlite' ) { - $db = new PDO( DB_DRIVER.':'.DB_NAME ); + $db = new PDO( DB_DRIVER.':'.dirname(__FILE__).DIRECTORY_SEPARATOR.DB_NAME ); } else { $db = new PDO ( DB_DRIVER.':host='.DB_SERVER.';dbname='.DB_NAME, DB_USERNAME, DB_PASSWORD ); From 29ac993b7c88a6d7f96d967dccd2d749526038d4 Mon Sep 17 00:00:00 2001 From: gtarasov Date: Thu, 11 Feb 2016 17:52:50 +0300 Subject: [PATCH 2/3] fixed stats for sqlite (now and week functions) --- -/stats.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) mode change 100755 => 100644 -/stats.php diff --git a/-/stats.php b/-/stats.php old mode 100755 new mode 100644 index 36e82a4..ef5ee32 --- a/-/stats.php +++ b/-/stats.php @@ -26,7 +26,8 @@ function stats_todays_stats($db, $count=false, $floor=0) { $db->exec('SET time_zone = "'. $offset .'";'); } $limit = ($count) ? " LIMIT {$count} " : ''; - $query = 'SELECT url_id, urls.url, urls.custom_url, COUNT(url_id) as hits FROM '. DB_PREFIX . 'url_stats LEFT JOIN '. DB_PREFIX .'urls as urls on ( urls.id = url_id ) WHERE DATE(created_on) = DATE(NOW()) GROUP BY url_id HAVING COUNT(url_id) > '. $floor .' ORDER BY hits DESC' . $limit; + $dateNow = (DB_DRIVER === 'sqlite' ? 'DATE(\'now\')' : 'DATE(NOW())'); + $query = 'SELECT url_id, urls.url, urls.custom_url, COUNT(url_id) as hits FROM '. DB_PREFIX . 'url_stats LEFT JOIN '. DB_PREFIX .'urls as urls on ( urls.id = url_id ) WHERE DATE(created_on) = '.$dateNow.' GROUP BY url_id HAVING COUNT(url_id) > '. $floor .' ORDER BY hits DESC' . $limit; $stmt = $db->query($query); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); return $rows; @@ -37,8 +38,11 @@ function stats_thisweeks_stats($db, $count=false, $floor=0) { $db->exec('SET time_zone = "'. $offset .'";'); } $limit = ($count) ? " LIMIT {$count} " : ''; - $query = 'SELECT url_id, urls.url, urls.custom_url, COUNT(url_id) as hits FROM '. DB_PREFIX . 'url_stats LEFT JOIN '. DB_PREFIX .'urls as urls on ( urls.id = url_id ) WHERE WEEK(created_on) = WEEK(NOW()) GROUP BY url_id HAVING COUNT(url_id) > '. $floor .' ORDER BY hits DESC' . $limit; - + + $weekCreatedOn = (DB_DRIVER === 'sqlite' ? 'strftime(\'%W\', created_on)' : 'WEEK(created_on)'); + $weekNow = (DB_DRIVER === 'sqlite' ? 'strftime(\'%W\', \'now\')' : 'WEEK(NOW())'); + $query = 'SELECT url_id, urls.url, urls.custom_url, COUNT(url_id) as hits FROM '. DB_PREFIX . 'url_stats LEFT JOIN '. DB_PREFIX .'urls as urls on ( urls.id = url_id ) WHERE '.$weekCreatedOn.' = '.$weekNow.' GROUP BY url_id HAVING COUNT(url_id) > '. $floor .' ORDER BY hits DESC' . $limit; + $stmt = $db->query($query); $rows = $stmt->fetchAll(PDO::FETCH_ASSOC); return $rows; From a5bc8e07b7524952ffbaba766c9839b4901d7600 Mon Sep 17 00:00:00 2001 From: gtarasov Date: Sat, 13 Feb 2016 02:59:04 +0300 Subject: [PATCH 3/3] removed LIMIT 1 for sqlite --- -/index.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/-/index.php b/-/index.php index 41bc527..2033ec6 100755 --- a/-/index.php +++ b/-/index.php @@ -524,7 +524,12 @@ function bc_log($message){ // This would deal with simultaneous inserts. $counter_update_sql = "UPDATE {$prefix}autoslug SET base10 = :base10 - WHERE method = :method LIMIT 1"; + WHERE method = :method"; + + if (DB_DRIVER !== 'sqlite') { + $counter_update_sql .= " LIMIT 1"; + } + $ctr_up = $db->prepare($counter_update_sql); $ctr_up_res = $ctr_up->execute(array( 'method' => AUTO_SLUG_METHOD, @@ -540,7 +545,7 @@ function bc_log($message){ $error = (string) $e2; bc_log('Could not update counter. '.$e2); } - + break; }