Support » Plugin: Missed Schedule Fix WP Failed Future Posts » Resolving table_name from query broken in select query

  • I am using sophisticated code that selects specific database + server depending on the table name the query is coming from (using hyperdb – scaling & performance reasons).

    When I used your plugin it didn’t work because your query is badly formatted. WordPress regepx to get table_name from your query isn’t working. I had to modify your code from:

    $sql = $wpdb->prepare(
    			"SELECT<code>ID</code>FROM<code>{$wpdb->posts}</code>"."WHERE("."((<code>post_date</code>>0)&&(<code>post_date</code><=%s))OR"."((<code>post_date_gmt</code>>0)&&(<code>post_date_gmt</code><=%s))".")AND<code>post_status</code>='future'LIMIT 10",
    			current_time( 'mysql' ),
    			current_time( 'mysql', 1 )
    			);

    to

    $qry = <<<SQL
    			SELECT <code>ID</code> FROM <code>{$wpdb->posts}</code> WHERE (
    				( <code>post_date</code> > 0 && <code>post_date</code> <= %s )
    				OR
    				( <code>post_date_gmt</code> > 0 && <code>post_date_gmt</code> <= %s )
    			)
    			AND <code>post_status</code> = 'future' LIMIT 10
    SQL;
    
    			$sql = $wpdb->prepare($qry,
    			current_time('mysql'),
    			current_time('mysql', 1)
    			);

    (with hyperdb)

    http://wordpress.org/extend/plugins/wp-missed-schedule/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor slangji

    (@slangji)

    @arkadiusz Rzadkowolski

    Your code work only with HyperDB, or work for all (single blog, multisite, use as CMS) with single standard db configuration?

    P.S. You have also a good idea to reduce db sql queries …

    My code only formats your query properly to work with hyperdb – works fine with normal wpdb class & others 🙂 No other changes were made.

    Your query is not working in this case, cause it doesn’t match such regexp due to no spaces between here

    'select<code>ID</code>FROM<code>{$wpdb->posts}</code>'

    (extracts table_name from query):

    // Quickly match most common queries
    		if ( preg_match('/^\s*(?:'
    				. 'SELECT.*?\s+FROM'
    				. '|INSERT(?:\s+IGNORE)?(?:\s+INTO)?'
    				. '|REPLACE(?:\s+INTO)?'
    				. '|UPDATE(?:\s+IGNORE)?'
    				. '|DELETE(?:\s+IGNORE)?(?:\s+FROM)?'
    				. ')\s+<code>?(\w+)</code>?/is', $q, $maybe) )
    			return $maybe[1];
    Plugin Contributor slangji

    (@slangji)

    OK! 🙂

    I modified Development Version with your code: please check that my modified everything is correct (new code inserted) and working well, both with hyperdb that with a normal db, before making the same changes on the stable tag … 😉

    Thanks!

    Plugin Contributor slangji

    (@slangji)

    This issue was inserted as Ticket #4218662 on to Todo List for Future Development.

    Thanks to Arkadiusz R. and all others was send me same solution via Contact form …

    If are satisfied of this plugin, please, consider one small Donation for my free work. 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Resolving table_name from query broken in select query’ is closed to new replies.