Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for sqlite #30

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion -/db.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
9 changes: 7 additions & 2 deletions -/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -540,7 +545,7 @@ function bc_log($message){
$error = (string) $e2;
bc_log('Could not update counter. '.$e2);
}

break;
}

Expand Down
10 changes: 7 additions & 3 deletions -/stats.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down