How do I execute the same stored procedure in multi-times in MySQL or PHP? -
In my I got a solution to figure out which data was duplicated before the merge data. This is a MySQL stored procedure to check the data:
drop process if check_user_files are available; DELIMITER \\ processing Create Chek_usr_failen (IN p_user_id INT, IN p_file_id CHAR (10)) If you already have available (SELECT then myTable WHERE user_id = p_user_id and File_id = P_file_id) 1 then myTable SET `file_status` = 0 where Ughr_aid = p_user_id and Update file_id = p_file_id; Sign in to my data (`user_id`,` file_status`, `file_id`) value (p_user_id, 0, p_file_id); end if; END \\ DELIMITER; To call the stored procedure:
Call check_gers_files ('1', '12'); table [myTable] composition: auto_id user_id file_id file_status 1 1 12 1 2 3 12 0 3 1 17 1 4 4 31 1 5 1 41 0 6 4 31 0 7 1 18 1 8 5 11 0 9 1 10 0 And my problem is, to check and insert me There is multi-data at the same time. Eg:
('1', '12'), ('2', '14'), ('3', '16'), ... < / Pre> But I can not call the stored procedure at the same time to check all the records at the same time. Easy:
call check_gers_file ('2', '12 '); Call check_user_files ('3', '12'); ... This only calls the first row of the stored procedure.
So, how can I see all the records in the same query at the same time? & Gt;
Thank you very much!
A single call can be performed using the stored procedure but not supporting mysql array parameters The reason is a bit ugly because we have to separate the string separated by user_id; File_id must pass in token. The only other option is to call the stored procedure multiple times.
Full script here:
mysql> * Choose from * User_files; + --------- + --------- + ------------- + | User_id | File_id | File_status | + --------- + --------- + ------------- + | 1 | 2 | 0 | | 3 | 6 | 0 | + --------- + --------- + ------------- + 2 lines set (0.00 seconds) Call check_user_file ('user_id; file_id, User_id; file_id ... '); Call check_user_files ('1; 2, 2; 4, 3; 6, 4; 10, 50; 50, 1000; 1, 1; 10001'); Mysql & gt; * Choose from * User_files; + --------- + --------- + ------------- + | User_id | File_id | File_status | + --------- + --------- + ------------- + | 1 | 2 | 0 | | 1 | 10001 | 0 | | 2 | 4 | 0 | | 3 | 6 | 0 | | 4 | 10 | 0 | | 50 | 50 | 0 | | 1000 | 1 | 0 | + --------- + --------- + ------------- + 7 lines set (0.00 seconds) Stored Process If the drop process is present check_user_files; Sequencing # Process check_asser_files (in p_users_files_csv varchar (4096)) Proc_main: Start declaring v_token varchar (255); Declared v_done tinyint unsigned default 0; Declared v_token_idx int unsigned default 1; Declared v_user_id int unsigned default 0; Declared v_file_id int unsigned default 0; Set p_users_files_csv = replace (p_users_files_csv, '', ''); If p_users_files_csv is zero or length (p_users_files_csv) & lt; = 0 then leave proc_man; end if; - real ugly bits - User_id / File_id to divide the string into tokens and put in in-memory tables ... temporary tables TMP (user_id int unsigned NOT NULL, File_id Int unsigned NOT NULL) ENGINE = memory; While v_done has not been set v_token = trim (substring (p_users_files_csv, v_token_idx, if (( ',', p_users_files_csv, v_token_idx) & gt; 0, locate ( ',', p_users_files_csv, v_token_idx) - v_token_idx, length ( p_users_files_csv))); if length (v_token) & gt; 0 then set v_token_idx = v_token_idx + length (v_token) + 1; set v_user_id = mid (v_token, 1, instr (v_token, ';') - 1); set v_file_id = mid (v_token, instr (v_token, ';') + 1, insert length (v_token)); Tmp (user_id, file_id) (v_user_id, v_file_id); another set v_done = 1; end if; end; - Good bit - Enter new value in user_file (user_id, file_id, file_status), t. Use Select T.Uzor_ID = UFUser_ID and T on the external user UFile UF from TMTT left-to-file TMTT by file tist teas as TFile_ID, 0.file_id = uf.file_id where uf.user_id is empty and uf.file_id is empty; If the temporary table drop is present; end proc_main # delimiter; Hope this helps
Comments
Post a Comment