WordPress.org

Ready to get started?Download WordPress

Forums

WP Missed Schedule Fix Failed Future Posts
[resolved] Resolving table_name from query broken in select query (5 posts)

  1. Arkadiusz Rzadkowolski
    Member
    Posted 11 months ago #

    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/

  2. sLa NGjI's
    Member
    Plugin Author

    Posted 11 months ago #

    @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 ...

  3. Arkadiusz Rzadkowolski
    Member
    Posted 10 months ago #

    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];
  4. sLa NGjI's
    Member
    Plugin Author

    Posted 10 months ago #

    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!

  5. sLa NGjI's
    Member
    Plugin Author

    Posted 10 months ago #

    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. :)

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.