* Return number of active users in database $table
Return number of active users in database $table
* @param $table
*/
* @return mixed|null
{
*/
functionqa_db_count_active_users($table)
{
switch($table){
switch($table){
case'posts':
case'posts':
case'uservotes':
case'uservotes':
...
@@ -113,63 +118,71 @@
...
@@ -113,63 +118,71 @@
}
}
returnqa_db_read_one_value(qa_db_query_sub(
returnqa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(DISTINCT(userid)) FROM ^'.$table
'SELECT COUNT(DISTINCT(userid)) FROM ^'.$table
));
));
}
}
functionqa_db_count_categories()
/**
/*
* Return number of categories in the database
Return number of categories in the database
*/
*/
functionqa_db_count_categories()
{
{
returnqa_db_read_one_value(qa_db_query_sub(
returnqa_db_read_one_value(qa_db_query_sub(
'SELECT COUNT(*) FROM ^categories'
'SELECT COUNT(*) FROM ^categories'
));
));
}
}
functionqa_db_count_categoryid_qs($categoryid)
/**
/*
* Return number of questions in the database in $categoryid exactly, and not one of its subcategories
Return number of questions in the database in $categoryid exactly, and not one of its subcategories
* @param $categoryid
*/
* @return mixed|null
{
*/
functionqa_db_count_categoryid_qs($categoryid)
{
returnqa_db_read_one_value(qa_db_query_sub(
returnqa_db_read_one_value(qa_db_query_sub(
"SELECT COUNT(*) FROM ^posts WHERE categoryid<=># AND type='Q'",
"SELECT COUNT(*) FROM ^posts WHERE categoryid<=># AND type='Q'",
$categoryid
$categoryid
));
));
}
}
functionqa_db_get_user_visible_postids($userid)
/**
/*
* Return list of postids of visible or queued posts by $userid
Return list of postids of visible or queued posts by $userid
* @param $userid
*/
* @return array
{
*/
functionqa_db_get_user_visible_postids($userid)
{
returnqa_db_read_all_values(qa_db_query_sub(
returnqa_db_read_all_values(qa_db_query_sub(
"SELECT postid FROM ^posts WHERE userid=# AND type IN ('Q', 'A', 'C', 'Q_QUEUED', 'A_QUEUED', 'C_QUEUED')",
"SELECT postid FROM ^posts WHERE userid=# AND type IN ('Q', 'A', 'C', 'Q_QUEUED', 'A_QUEUED', 'C_QUEUED')",
$userid
$userid
));
));
}
}
functionqa_db_get_ip_visible_postids($ip)
/**
/*
* Return list of postids of visible or queued posts from $ip address
Return list of postids of visible or queued posts from $ip address
* @param $ip
*/
* @return array
{
*/
functionqa_db_get_ip_visible_postids($ip)
{
returnqa_db_read_all_values(qa_db_query_sub(
returnqa_db_read_all_values(qa_db_query_sub(
"SELECT postid FROM ^posts WHERE createip=$ AND type IN ('Q', 'A', 'C', 'Q_QUEUED', 'A_QUEUED', 'C_QUEUED')",
"SELECT postid FROM ^posts WHERE createip=$ AND type IN ('Q', 'A', 'C', 'Q_QUEUED', 'A_QUEUED', 'C_QUEUED')",
@inet_pton($ip)
@inet_pton($ip)
));
));
}
}
functionqa_db_postids_count_dependents($postids)
/**
/*
* Return an array whose keys contain the $postids which exist, and whose elements contain the number of other posts depending on each one
Return an array whose keys contain the $postids which exist, and whose elements contain the number of other posts depending on each one
* @param $postids
*/
* @return array
{
*/
functionqa_db_postids_count_dependents($postids)
{
if(count($postids))
if(count($postids))
returnqa_db_read_all_assoc(qa_db_query_sub(
returnqa_db_read_all_assoc(qa_db_query_sub(
"SELECT postid, COALESCE(childcount, 0) AS count FROM ^posts LEFT JOIN (SELECT parentid, COUNT(*) AS childcount FROM ^posts WHERE parentid IN (#) AND LEFT(type, 1) IN ('A', 'C') GROUP BY parentid) x ON postid=x.parentid WHERE postid IN (#)",
"SELECT postid, COALESCE(childcount, 0) AS count FROM ^posts LEFT JOIN (SELECT parentid, COUNT(*) AS childcount FROM ^posts WHERE parentid IN (#) AND LEFT(type, 1) IN ('A', 'C') GROUP BY parentid) x ON postid=x.parentid WHERE postid IN (#)",
...
@@ -177,234 +190,270 @@
...
@@ -177,234 +190,270 @@
),'postid','count');
),'postid','count');
else
else
returnarray();
returnarray();
}
}
functionqa_db_get_unapproved_users($count)
/**
/*
* Return an array of the (up to) $count most recently created users who are awaiting approval and have not been blocked.
Return an array of the (up to) $count most recently created users who are awaiting approval and have not been blocked.
* The array element for each user includes a 'profile' key whose value is an array of non-empty profile fields of the user.
The array element for each user includes a 'profile' key whose value is an array of non-empty profile fields of the user.
* @param $count
*/
* @return array
{
*/
$results=qa_db_read_all_assoc(qa_db_query_sub(
functionqa_db_get_unapproved_users($count)
{
$results=qa_db_read_all_assoc(qa_db_query_sub(
"SELECT ^users.userid, UNIX_TIMESTAMP(created) AS created, createip, email, handle, flags, title, content FROM ^users LEFT JOIN ^userprofile ON ^users.userid=^userprofile.userid AND LENGTH(content)>0 WHERE level<# AND NOT (flags&#) ORDER BY created DESC LIMIT #",
"SELECT ^users.userid, UNIX_TIMESTAMP(created) AS created, createip, email, handle, flags, title, content FROM ^users LEFT JOIN ^userprofile ON ^users.userid=^userprofile.userid AND LENGTH(content)>0 WHERE level<# AND NOT (flags&#) ORDER BY created DESC LIMIT #",
* Return whether there are any blobs whose content has been stored as a file on disk
Return whether there are any blobs whose content has been stored as a file on disk
*/
*/
functionqa_db_has_blobs_on_disk()
{
{
returnqa_db_read_one_value(qa_db_query_sub('SELECT blobid FROM ^blobs WHERE content IS NULL LIMIT 1'),true)!=null;
returnqa_db_read_one_value(qa_db_query_sub('SELECT blobid FROM ^blobs WHERE content IS NULL LIMIT 1'),true)!=null;
}
}
functionqa_db_has_blobs_in_db()
/**
/*
* Return whether there are any blobs whose content has been stored in the database
Return whether there are any blobs whose content has been stored in the database
*/
*/
functionqa_db_has_blobs_in_db()
{
{
returnqa_db_read_one_value(qa_db_query_sub('SELECT blobid FROM ^blobs WHERE content IS NOT NULL LIMIT 1'),true)!=null;
returnqa_db_read_one_value(qa_db_query_sub('SELECT blobid FROM ^blobs WHERE content IS NOT NULL LIMIT 1'),true)!=null;
}
}
functionqa_db_category_last_pos($parentid)
/**
/*
* Return the maximum position of the categories with $parentid
Return the maximum position of the categories with $parentid
* @param $parentid
*/
* @return mixed|null
{
*/
functionqa_db_category_last_pos($parentid)
{
returnqa_db_read_one_value(qa_db_query_sub(
returnqa_db_read_one_value(qa_db_query_sub(
'SELECT COALESCE(MAX(position), 0) FROM ^categories WHERE parentid<=>#',
'SELECT COALESCE(MAX(position), 0) FROM ^categories WHERE parentid<=>#',
$parentid
$parentid
));
));
}
}
functionqa_db_category_child_depth($categoryid)
/**
/*
* Return how many levels of subcategory there are below $categoryid
Return how many levels of subcategory there are below $categoryid
* @param $categoryid
*/
* @return int
{
*/
functionqa_db_category_child_depth($categoryid)
{
// This is potentially a very slow query since it counts all the multi-generational offspring of a particular category
// This is potentially a very slow query since it counts all the multi-generational offspring of a particular category
// But it's only used for admin purposes when moving a category around so I don't think it's worth making more efficient
// But it's only used for admin purposes when moving a category around so I don't think it's worth making more efficient
// (Incidentally, this could be done by keeping a count for every category of how many generations of offspring it has.)
// (Incidentally, this could be done by keeping a count for every category of how many generations of offspring it has.)
$result=qa_db_read_one_assoc(qa_db_query_sub(
$result=qa_db_read_one_assoc(qa_db_query_sub(
'SELECT COUNT(child1.categoryid) AS count1, COUNT(child2.categoryid) AS count2, COUNT(child3.categoryid) AS count3 FROM ^categories AS child1 LEFT JOIN ^categories AS child2 ON child2.parentid=child1.categoryid LEFT JOIN ^categories AS child3 ON child3.parentid=child2.categoryid WHERE child1.parentid=#;',// requires QA_CATEGORY_DEPTH=4
'SELECT COUNT(child1.categoryid) AS count1, COUNT(child2.categoryid) AS count2, COUNT(child3.categoryid) AS count3 FROM ^categories AS child1 LEFT JOIN ^categories AS child2 ON child2.parentid=child1.categoryid LEFT JOIN ^categories AS child3 ON child3.parentid=child2.categoryid WHERE child1.parentid=#;',// requires QA_CATEGORY_DEPTH=4
"UPDATE ^categories AS x, (SELECT cat1.categoryid, CONCAT_WS('/', cat1.tags, cat2.tags, cat3.tags, cat4.tags) AS backpath FROM ^categories AS cat1 LEFT JOIN ^categories AS cat2 ON cat1.parentid=cat2.categoryid LEFT JOIN ^categories AS cat3 ON cat2.parentid=cat3.categoryid LEFT JOIN ^categories AS cat4 ON cat3.parentid=cat4.categoryid WHERE cat1.categoryid BETWEEN # AND #) AS a SET x.backpath=a.backpath WHERE x.categoryid=a.categoryid",
"UPDATE ^categories AS x, (SELECT cat1.categoryid, CONCAT_WS('/', cat1.tags, cat2.tags, cat3.tags, cat4.tags) AS backpath FROM ^categories AS cat1 LEFT JOIN ^categories AS cat2 ON cat1.parentid=cat2.categoryid LEFT JOIN ^categories AS cat3 ON cat2.parentid=cat3.categoryid LEFT JOIN ^categories AS cat4 ON cat3.parentid=cat4.categoryid WHERE cat1.categoryid BETWEEN # AND #) AS a SET x.backpath=a.backpath WHERE x.categoryid=a.categoryid",
$andsql=isset($conditionsql)?(' AND '.$conditionsql):'';
qa_db_query_sub('LOCK TABLES ^'.$table.' WRITE');
qa_db_query_sub('LOCK TABLES ^'.$table.' WRITE');
$oldposition=qa_db_read_one_value(qa_db_query_sub('SELECT position FROM ^'.$table.' WHERE '.$idcolumn.'=#'.$andsql,$id));
$oldposition=qa_db_read_one_value(qa_db_query_sub('SELECT position FROM ^'.$table.' WHERE '.$idcolumn.'=#'.$andsql,$id));
if($newposition!=$oldposition){
if($newposition!=$oldposition){
$lastposition=qa_db_read_one_value(qa_db_query_sub('SELECT MAX(position) FROM ^'.$table.' WHERE TRUE'.$andsql));
$lastposition=qa_db_read_one_value(qa_db_query_sub('SELECT MAX(position) FROM ^'.$table.' WHERE TRUE'.$andsql));
$newposition=max(1,min($newposition,$lastposition));// constrain it to within range
$newposition=max(1,min($newposition,$lastposition));// constrain it to within range
qa_db_query_sub('UPDATE ^'.$table.' SET position=# WHERE '.$idcolumn.'=#'.$andsql,1+$lastposition,$id);
// move it temporarily off the top because we have a unique key on the position column
// move it temporarily off the top because we have a unique key on the position column
qa_db_query_sub('UPDATE ^'.$table.' SET position=# WHERE '.$idcolumn.'=#'.$andsql,1+$lastposition,$id);
if($newposition<$oldposition)
if($newposition<$oldposition)
qa_db_query_sub('UPDATE ^'.$table.' SET position=position+1 WHERE position BETWEEN # AND #'.$andsql.' ORDER BY position DESC',$newposition,$oldposition);
qa_db_query_sub('UPDATE ^'.$table.' SET position=position+1 WHERE position BETWEEN # AND #'.$andsql.' ORDER BY position DESC',$newposition,$oldposition);
else
else
qa_db_query_sub('UPDATE ^'.$table.' SET position=position-1 WHERE position BETWEEN # AND #'.$andsql.' ORDER BY position',$oldposition,$newposition);
qa_db_query_sub('UPDATE ^'.$table.' SET position=position-1 WHERE position BETWEEN # AND #'.$andsql.' ORDER BY position',$oldposition,$newposition);
qa_db_query_sub('UPDATE ^'.$table.' SET position=# WHERE '.$idcolumn.'=#'.$andsql,$newposition,$id);
qa_db_query_sub('UPDATE ^'.$table.' SET position=# WHERE '.$idcolumn.'=#'.$andsql,$newposition,$id);
qa_db_upgrade_query('UPDATE ^posts SET updated=NULL WHERE updated=0 OR updated=created');
qa_db_upgrade_query('UPDATE ^posts SET updated=NULL WHERE updated=0 OR updated=created');
break;
break;
case5:
case5:
qa_db_upgrade_query('ALTER TABLE ^contentwords ADD COLUMN type '.$definitions['contentwords']['type'].' AFTER count, ADD COLUMN questionid '.$definitions['contentwords']['questionid'].' AFTER type');
qa_db_upgrade_query('ALTER TABLE ^contentwords ADD COLUMN type '.$definitions['contentwords']['type'].' AFTER count, ADD COLUMN questionid '.$definitions['contentwords']['questionid'].' AFTER type');
qa_db_upgrade_query($locktablesquery);
qa_db_upgrade_query($locktablesquery);
$keyrecalc['doreindexcontent']=true;
$keyrecalc['doreindexcontent']=true;
break;
break;
// Up to here: Version 1.0 beta 2
// Up to here: Version 1.0 beta 2
case6:
case6:
qa_db_upgrade_query('ALTER TABLE ^userpoints ADD COLUMN cposts '.$definitions['userpoints']['cposts'].' AFTER aposts');
qa_db_upgrade_query('ALTER TABLE ^userpoints ADD COLUMN cposts '.$definitions['userpoints']['cposts'].' AFTER aposts');
qa_db_upgrade_query($locktablesquery);
qa_db_upgrade_query($locktablesquery);
$keyrecalc['dorecalcpoints']=true;
$keyrecalc['dorecalcpoints']=true;
break;
break;
case7:
case7:
if(!QA_FINAL_EXTERNAL_USERS){
if(!QA_FINAL_EXTERNAL_USERS){
qa_db_upgrade_query('ALTER TABLE ^users ADD COLUMN sessioncode '.$definitions['users']['sessioncode'].' AFTER writeip');
qa_db_upgrade_query('ALTER TABLE ^users ADD COLUMN sessioncode '.$definitions['users']['sessioncode'].' AFTER writeip');
qa_db_upgrade_query('UPDATE ^posts SET lastviewip = UNHEX(HEX(CAST(lastviewip AS UNSIGNED))), lastip = UNHEX(HEX(CAST(lastip AS UNSIGNED))), createip = UNHEX(HEX(CAST(createip AS UNSIGNED)))');
qa_db_upgrade_query('UPDATE ^posts SET lastviewip = UNHEX(HEX(CAST(lastviewip AS UNSIGNED))), lastip = UNHEX(HEX(CAST(lastip AS UNSIGNED))), createip = UNHEX(HEX(CAST(createip AS UNSIGNED)))');
qa_db_upgrade_query('UPDATE ^users SET createip = UNHEX(HEX(CAST(createip AS UNSIGNED))), loginip = UNHEX(HEX(CAST(loginip AS UNSIGNED))), writeip = UNHEX(HEX(CAST(writeip AS UNSIGNED)))');
qa_db_upgrade_query('UPDATE ^users SET createip = UNHEX(HEX(CAST(createip AS UNSIGNED))), loginip = UNHEX(HEX(CAST(loginip AS UNSIGNED))), writeip = UNHEX(HEX(CAST(writeip AS UNSIGNED)))');
}
}
}
}
...
@@ -1529,7 +1540,7 @@
...
@@ -1529,7 +1540,7 @@
qa_db_set_db_version($newversion);
qa_db_set_db_version($newversion);
if(qa_db_get_db_version()!=$newversion)
if(qa_db_get_db_version()!=$newversion)
qa_fatal_error('Could not increment database version');
qa_fatal_error('Could not increment database version');
"SELECT ^posts.postid, ^posts.title, ^posts.content, ^posts.format, ^posts.tags, ^posts.categoryid, ^posts.type, IF (^posts.type='Q', ^posts.postid, IF(parent.type='Q', parent.postid, grandparent.postid)) AS questionid, ^posts.parentid FROM ^posts LEFT JOIN ^posts AS parent ON ^posts.parentid=parent.postid LEFT JOIN ^posts as grandparent ON parent.parentid=grandparent.postid WHERE ^posts.postid>=# AND ( (^posts.type='Q') OR (^posts.type='A' AND parent.type<=>'Q') OR (^posts.type='C' AND parent.type<=>'Q') OR (^posts.type='C' AND parent.type<=>'A' AND grandparent.type<=>'Q') ) ORDER BY postid LIMIT #",
"SELECT ^posts.postid, ^posts.title, ^posts.content, ^posts.format, ^posts.tags, ^posts.categoryid, ^posts.type, IF (^posts.type='Q', ^posts.postid, IF(parent.type='Q', parent.postid, grandparent.postid)) AS questionid, ^posts.parentid FROM ^posts LEFT JOIN ^posts AS parent ON ^posts.parentid=parent.postid LEFT JOIN ^posts as grandparent ON parent.parentid=grandparent.postid WHERE ^posts.postid>=# AND ( (^posts.type='Q') OR (^posts.type='A' AND parent.type<=>'Q') OR (^posts.type='C' AND parent.type<=>'Q') OR (^posts.type='C' AND parent.type<=>'A' AND grandparent.type<=>'Q') ) ORDER BY postid LIMIT #",
'UPDATE ^words AS x, (SELECT ^words.wordid, COUNT(^titlewords.wordid) AS titlecount FROM ^words LEFT JOIN ^titlewords ON ^titlewords.wordid=^words.wordid WHERE ^words.wordid>=# AND ^words.wordid<=# GROUP BY wordid) AS a SET x.titlecount=a.titlecount WHERE x.wordid=a.wordid',
'UPDATE ^words AS x, (SELECT ^words.wordid, COUNT(^titlewords.wordid) AS titlecount FROM ^words LEFT JOIN ^titlewords ON ^titlewords.wordid=^words.wordid WHERE ^words.wordid>=# AND ^words.wordid<=# GROUP BY wordid) AS a SET x.titlecount=a.titlecount WHERE x.wordid=a.wordid',
$firstwordid,$lastwordid
$firstwordid,$lastwordid
...
@@ -173,43 +187,50 @@
...
@@ -173,43 +187,50 @@
'DELETE FROM ^words WHERE wordid>=# AND wordid<=# AND titlecount=0 AND contentcount=0 AND tagwordcount=0 AND tagcount=0',
'DELETE FROM ^words WHERE wordid>=# AND wordid<=# AND titlecount=0 AND contentcount=0 AND tagwordcount=0 AND tagcount=0',
$firstwordid,$lastwordid
$firstwordid,$lastwordid
);
);
}
}
// For recalculating numbers of votes and answers for questions...
// For recalculating numbers of votes and answers for questions...
'UPDATE ^posts AS x, (SELECT ^posts.postid, COALESCE(SUM(GREATEST(0,^uservotes.vote)),0) AS upvotes, -COALESCE(SUM(LEAST(0,^uservotes.vote)),0) AS downvotes, COALESCE(SUM(IF(^uservotes.flag, 1, 0)),0) AS flagcount FROM ^posts LEFT JOIN ^uservotes ON ^uservotes.postid=^posts.postid WHERE ^posts.postid>=# AND ^posts.postid<=# GROUP BY postid) AS a SET x.upvotes=a.upvotes, x.downvotes=a.downvotes, x.netvotes=a.upvotes-a.downvotes, x.flagcount=a.flagcount WHERE x.postid=a.postid',
'UPDATE ^posts AS x, (SELECT ^posts.postid, COALESCE(SUM(GREATEST(0,^uservotes.vote)),0) AS upvotes, -COALESCE(SUM(LEAST(0,^uservotes.vote)),0) AS downvotes, COALESCE(SUM(IF(^uservotes.flag, 1, 0)),0) AS flagcount FROM ^posts LEFT JOIN ^uservotes ON ^uservotes.postid=^posts.postid WHERE ^posts.postid>=# AND ^posts.postid<=# GROUP BY postid) AS a SET x.upvotes=a.upvotes, x.downvotes=a.downvotes, x.netvotes=a.upvotes-a.downvotes, x.flagcount=a.flagcount WHERE x.postid=a.postid',
'UPDATE ^posts AS x, (SELECT parents.postid, COUNT(children.postid) AS acount, COALESCE(GREATEST(MAX(children.netvotes), 0), 0) AS amaxvote FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type=\'A\' WHERE parents.postid>=# AND parents.postid<=# GROUP BY postid) AS a SET x.acount=a.acount, x.amaxvote=a.amaxvote WHERE x.postid=a.postid',
'UPDATE ^posts AS x, (SELECT parents.postid, COUNT(children.postid) AS acount, COALESCE(GREATEST(MAX(children.netvotes), 0), 0) AS amaxvote FROM ^posts AS parents LEFT JOIN ^posts AS children ON parents.postid=children.parentid AND children.type=\'A\' WHERE parents.postid>=# AND parents.postid<=# GROUP BY postid) AS a SET x.acount=a.acount, x.amaxvote=a.amaxvote WHERE x.postid=a.postid',
'SELECT userid FROM ((SELECT DISTINCT userid FROM ^posts WHERE userid>=# ORDER BY userid LIMIT #) UNION (SELECT DISTINCT userid FROM ^uservotes WHERE userid>=# ORDER BY userid LIMIT #)) x ORDER BY userid LIMIT #',
'SELECT userid FROM ((SELECT DISTINCT userid FROM ^posts WHERE userid>=# ORDER BY userid LIMIT #) UNION (SELECT DISTINCT userid FROM ^uservotes WHERE userid>=# ORDER BY userid LIMIT #)) x ORDER BY userid LIMIT #',
...
@@ -238,29 +262,31 @@
...
@@ -238,29 +262,31 @@
'SELECT DISTINCT userid FROM ^users WHERE userid>=# ORDER BY userid LIMIT #',
'SELECT DISTINCT userid FROM ^users WHERE userid>=# ORDER BY userid LIMIT #',
"UPDATE ^posts AS x, (SELECT ^posts.postid, IF(LEFT(parent.type, 1)='Q', parent.categoryid, grandparent.categoryid) AS categoryid FROM ^posts LEFT JOIN ^posts AS parent ON ^posts.parentid=parent.postid LEFT JOIN ^posts AS grandparent ON parent.parentid=grandparent.postid WHERE ^posts.postid BETWEEN # AND # AND LEFT(^posts.type, 1)!='Q') AS a SET x.categoryid=a.categoryid WHERE x.postid=a.postid",
"UPDATE ^posts AS x, (SELECT ^posts.postid, IF(LEFT(parent.type, 1)='Q', parent.categoryid, grandparent.categoryid) AS categoryid FROM ^posts LEFT JOIN ^posts AS parent ON ^posts.parentid=parent.postid LEFT JOIN ^posts AS grandparent ON parent.parentid=grandparent.postid WHERE ^posts.postid BETWEEN # AND # AND LEFT(^posts.type, 1)!='Q') AS a SET x.categoryid=a.categoryid WHERE x.postid=a.postid",
$limitsql=isset($limit)?(' ORDER BY ^posts.postid LIMIT '.(int)$limit):'';
returnqa_db_read_all_values(qa_db_query_sub(
returnqa_db_read_all_values(qa_db_query_sub(
"SELECT ^posts.postid FROM ^posts LEFT JOIN ^posts AS child ON child.parentid=^posts.postid LEFT JOIN ^posts AS dupe ON dupe.closedbyid=^posts.postid WHERE ^posts.type=$ AND ^posts.postid>=# AND child.postid IS NULL AND dupe.postid IS NULL".$limitsql,
"SELECT ^posts.postid FROM ^posts LEFT JOIN ^posts AS child ON child.parentid=^posts.postid LEFT JOIN ^posts AS dupe ON dupe.closedbyid=^posts.postid WHERE ^posts.type=$ AND ^posts.postid>=# AND child.postid IS NULL AND dupe.postid IS NULL".$limitsql,
$type.'_HIDDEN',$startpostid
$type.'_HIDDEN',$startpostid
));
));
}
}
// For moving blobs between database and disk...
// For moving blobs between database and disk...
functionqa_db_count_blobs_in_db()
/**
/*
* Return the number of blobs whose content is stored in the database, rather than on disk
Return the number of blobs whose content is stored in the database, rather than on disk
*/
*/
functionqa_db_count_blobs_in_db()
{
{
returnqa_db_read_one_value(qa_db_query_sub('SELECT COUNT(*) FROM ^blobs WHERE content IS NOT NULL'));
returnqa_db_read_one_value(qa_db_query_sub('SELECT COUNT(*) FROM ^blobs WHERE content IS NOT NULL'));
}
}
functionqa_db_get_next_blob_in_db($startblobid)
/**
/*
* Return the id, content and format of the first blob whose content is stored in the database starting from $startblobid
Return the id, content and format of the first blob whose content is stored in the database starting from $startblobid
* @param $startblobid
*/
* @return array|null
{
*/
functionqa_db_get_next_blob_in_db($startblobid)
{
returnqa_db_read_one_assoc(qa_db_query_sub(
returnqa_db_read_one_assoc(qa_db_query_sub(
'SELECT blobid, content, format FROM ^blobs WHERE blobid>=# AND content IS NOT NULL LIMIT 1',
'SELECT blobid, content, format FROM ^blobs WHERE blobid>=# AND content IS NOT NULL LIMIT 1',
$startblobid
$startblobid
),true);
),true);
}
}
functionqa_db_count_blobs_on_disk()
/**
/*
* Return the number of blobs whose content is stored on disk, rather than in the database
Return the number of blobs whose content is stored on disk, rather than in the database
*/
*/
functionqa_db_count_blobs_on_disk()
{
{
returnqa_db_read_one_value(qa_db_query_sub('SELECT COUNT(*) FROM ^blobs WHERE content IS NULL'));
returnqa_db_read_one_value(qa_db_query_sub('SELECT COUNT(*) FROM ^blobs WHERE content IS NULL'));
}
}
functionqa_db_get_next_blob_on_disk($startblobid)
/**
/*
* Return the id and format of the first blob whose content is stored on disk starting from $startblobid
Return the id and format of the first blob whose content is stored on disk starting from $startblobid
* @param $startblobid
*/
* @return array|null
{
*/
functionqa_db_get_next_blob_on_disk($startblobid)
{
returnqa_db_read_one_assoc(qa_db_query_sub(
returnqa_db_read_one_assoc(qa_db_query_sub(
'SELECT blobid, format FROM ^blobs WHERE blobid>=# AND content IS NULL LIMIT 1',
'SELECT blobid, format FROM ^blobs WHERE blobid>=# AND content IS NULL LIMIT 1',
$startblobid
$startblobid
),true);
),true);
}
}
/*
Omit PHP closing tag to help avoid accidental output