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

sqlite3 #82

Merged
merged 3 commits into from
Oct 20, 2012
Merged
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
10 changes: 8 additions & 2 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ function forAdminOnly() { return false; }
function admin_plugin_blogtng() {
$this->commenthelper =& plugin_load('helper', 'blogtng_comments');
$this->entryhelper =& plugin_load('helper', 'blogtng_entry');
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');

if ($this->getConf('sqlite_version') == 'SQLite2')
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
else
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite3');


$this->taghelper =& plugin_load('helper', 'blogtng_tags');
}

Expand Down Expand Up @@ -282,7 +288,7 @@ function xhtml_search_result($resid, $query, $callback) {
// FIXME selectable?
$limit = 20;

$count = sqlite_num_rows($resid);
$count = $this->sqlitehelper->resRowCount($resid);
$start = (isset($_REQUEST['btng']['query']['start'])) ? ($_REQUEST['btng']['query']['start']) : 0;
$end = ($count >= ($start + $limit)) ? ($start + $limit) : $count;
$cur = ($start / $limit) + 1;
Expand Down
1 change: 1 addition & 0 deletions conf/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
$conf['tags'] = '';
$conf['receive_linkbacks'] = 1;
$conf['send_linkbacks'] = 0;
$conf['sqlite_version'] = 'SQLite3';
1 change: 1 addition & 0 deletions conf/metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
$meta['tags'] = array('string');
$meta['receive_linkbacks'] = array('onoff');
$meta['send_linkbacks'] = array('onoff');
$meta['sqlite_version'] = array('multichoice', '_choices' => array('SQLite2', 'SQLite3'));
15 changes: 10 additions & 5 deletions helper/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ class helper_plugin_blogtng_comments extends DokuWiki_Plugin {
* Constructor, loads the sqlite helper plugin
*/
function helper_plugin_blogtng_comments() {
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
//$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
if ($this->getConf('sqlite_version') == 'SQLite2')
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
else
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite3');

}

/**
Expand Down Expand Up @@ -48,7 +53,7 @@ function comment_by_cid($cid) {
if ($resid === false) {
return false;
}
if (sqlite_num_rows($resid) == 0) {
if ($this->sqlitehelper->resRowCount($resid) == 0) {
return null;
}
$result = $this->sqlitehelper->res2arr($resid);
Expand Down Expand Up @@ -311,7 +316,7 @@ function unsubscribe_by_key($pid, $key) {
function unsubscribe($pid, $mail) {
$sql = 'DELETE FROM subscriptions WHERE pid = ? AND mail = ?';
$this->sqlitehelper->query($sql, $pid, $mail);
$upd = sqlite_changes($this->sqlitehelper->db);
$upd = $this->sqlitehelper->changes();
if ($upd) {
msg($this->getLang('unsubscribe_ok'), 1);
} else {
Expand All @@ -325,7 +330,7 @@ function unsubscribe($pid, $mail) {
function optin($key) {
$sql = 'UPDATE optin SET optin = 1 WHERE key = ?';
$this->sqlitehelper->query($sql,$key);
$upd = sqlite_changes($this->sqlitehelper->db);
$upd = $this->sqlitehelper->changes();

if($upd){
msg($this->getLang('optin_ok'),1);
Expand Down Expand Up @@ -532,7 +537,7 @@ function tpl_recentcomments($tpl='default',$num=5,$blogs=array('default'),$types
LIMIT ".(int) $num;

$res = $this->sqlitehelper->query($query);
if(!sqlite_num_rows($res)) return; // no results found
if(!$this->sqlitehelper->resRowCount($res)) return; // no results found
$res = $this->sqlitehelper->res2arr($res);

// print all hits using the template
Expand Down
15 changes: 10 additions & 5 deletions helper/entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class helper_plugin_blogtng_entry extends DokuWiki_Plugin {
* @author Michael Klier <chi@chimeric.de>
*/
function helper_plugin_blogtng_entry() {
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
//$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
if ($this->getConf('sqlite_version') == 'SQLite2')
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
else
$this->sqlitehelper =& plugin_load('helper', 'blogtng_sqlite3');

$this->entry = $this->prototype();
}

Expand All @@ -60,7 +65,7 @@ function load_by_pid($pid) {
$this->entry = $this->prototype();
return self::RET_ERR_DB;
}
if (sqlite_num_rows($resid) == 0) {
if ($this->sqlitehelper->resRowCount($resid) == 0) {
$this->entry = $this->prototype();
$this->entry['pid'] = $pid;
return self::RET_ERR_NOENTRY;
Expand Down Expand Up @@ -266,7 +271,7 @@ function xhtml_pagination($conf){
WHERE '.$blog_query.$tag_query;
$resid = $this->sqlitehelper->query($query);
if (!$resid) return;
$count = sqlite_num_rows($resid);
$count = $this->sqlitehelper->resRowCount($resid);
if($count <= $conf['limit']) return '';

// we now prepare an array of pages to show
Expand Down Expand Up @@ -540,7 +545,7 @@ function tpl_related($num=5,$blogs=array('default'),$id=false,$tags=array()){
ORDER BY cnt DESC, created DESC
LIMIT ".(int) $num;
$res = $this->sqlitehelper->query($query);
if(!sqlite_num_rows($res)) return; // no results found
if(!$this->sqlitehelper->resRowCount($res)) return; // no results found
$res = $this->sqlitehelper->res2arr($res);

// now do the output
Expand Down Expand Up @@ -770,7 +775,7 @@ function getAdjacentLinks($id = false) {
ORDER BY A.created ' . (($type == 'prev') ? 'DESC' : 'ASC') . '
LIMIT 1';
$res = $this->sqlitehelper->query($query, $pid);
if (sqlite_num_rows($res) > 0) {
if ($this->sqlitehelper->resRowCount($res) > 0) {
$row = $this->sqlitehelper->res2row($res, 0);
$related[$type] = $row;
}
Expand Down
6 changes: 5 additions & 1 deletion helper/linkback.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public function saveLinkback($type, $title, $sourceUri, $excerpt, $id) {
'status' => 'hidden',
'ip' => clientIP(true));

$sqlitehelper = plugin_load('helper', 'blogtng_sqlite');
if ($this->getConf('sqlite_version') == 'SQLite2')
$sqlitehelper =& plugin_load('helper', 'blogtng_sqlite');
else
$sqlitehelper =& plugin_load('helper', 'blogtng_sqlite3');

$query = 'SELECT web, source FROM comments WHERE pid = ?';

$resid = $sqlitehelper->query($query, $comment['pid']);
Expand Down
19 changes: 19 additions & 0 deletions helper/sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,25 @@ function res2row($res,$rownum=0){
}


/**
* Return count of elements in result set
* @param $res
* @return int
*/
function resRowCount($res){
return sqlite_num_rows($res);
}


/**
* Return count of changes after last update
* @return mixed
*/
function changes(){
return sqlite_changes($this->db);
}


/**
* Join the given values and quote them for SQL insertion
*/
Expand Down
Loading