• Resolved francescjp

    (@francescjp)


    Hello:

    I am creating a plugin in which I create a custom table in activate event. I use this combination of functions to get it:

    
    $sql=file_get_contents( plugin_dir_url(__FILE__) . 'sql/wp_codis_postals.sql', FILE_USE_INCLUDE_PATH);
    
    dbDelta( $sql );
    

    This sql file contains insertion of more than 1500 records. I attach the code with only 5 insertions. The code generates no error but no record is being inserted on table. If I echo the sql file, copy it to phpmysqladmin and execute it, the records are created without problem. Could be the problem of charset or something like this? Anyone knows the reason?

    Thank you very much.

    
    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET time_zone = "+00:00";
    
    CREATE TABLE IF NOT EXISTS <code>wp_codis_postals</code> (
      <code>codi_postal</code> int(5) NOT NULL DEFAULT 0,
      <code>poblacio</code> varchar(75) CHARACTER SET utf8 COLLATE utf8_spanish2_ci NOT NULL DEFAULT '',
      PRIMARY KEY (<code>codi_postal</code>,<code>poblacio</code>)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    DELIMITER ;;
    
    DROP PROCEDURE IF EXISTS usp_test_transaction ;;
    CREATE PROCEDURE usp_test_transaction()
    
    BEGIN
    
    DECLARE total INT DEFAULT 0;
    
    SELECT COUNT(*) 
        INTO total
        FROM wp_codis_postals;
    
    IF (total<=0) THEN
    
    INSERT INTO <code>wp_codis_postals</code> (<code>codi_postal</code>, <code>poblacio</code>) VALUES
    (43890, 'Vandellòs i l\'Hospitalet de l\'Infant'),
    (43891, 'Pratdip'),
    (43891, 'Vandellòs i l\'Hospitalet de l\'Infant'),
    (43892, 'Mont-roig del Camp'),
    (43893, 'Altafulla'),
    (43894, 'Camarles'),
    (43895, 'Ampolla, l\''),
    (43896, 'Aldea, l\''),
    (43897, 'Tortosa');
    
    END IF;
    
    END ;;
    
    call usp_test_transaction;
    
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘dbdelta problem on activate event with large content’ is closed to new replies.