ansonphong / postworld

Wordpress Theme Development Framework
GNU General Public License v2.0
7 stars 0 forks source link

set_post_relationship() PHP Errors when user_meta row or column are empty #60

Closed ansonphong closed 10 years ago

ansonphong commented 10 years ago

Hi Haidy, There are two cases to investigate here:

Case 1

When using the set_favorite() method, it gives this error :

WordPress database error: [Unknown column 'share_points_meta' in 'field list']
INSERT INTO `wp_postworld_user_meta` (`user_id`, `post_points`, `post_points_meta`, `comment_points`, `share_points`, `share_points_meta`, `post_relationships`, `post_votes`, `comment_votes`, `location_city`, `location_region`, `location_country`) VALUES (1,0,null,0,0,null,null,null,null,null,null,null);

WordPress database error: [Column count doesn't match value count at row 1]
insert into wp_postworld_favorites values (1,178475,null)

We will want this function to handle the use-case where the user_id doesn't have a row yet in postworld_user_meta table.

Case 2

So I created a row in the postworld_user_meta table for my user_id, and it gives this error the first time adding a favorite: ( 1, is my username, 178475 is the post_id I'm trying to set as favorite )

WordPress database error: [Column count doesn't match value count at row 1]
insert into wp_postworld_favorites values (1,178475,null)

At the same time it does create the following value in post_relationships column:

{"viewed":[],"favorites":["178475"],"view_later":[]}

And the second time running (on the same post ID), it produces no error. Though running it on a new post_id again produces the second error.

Conclusion

We will want the set_post_relationship() function to handle cases where the user_id row, and/or the post_relationships column are empty, and when adding a post_id for the first time.

ansonphong commented 10 years ago

Additionally, when using set_view_later() the following errors are produced every time.

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
select post_relationships from wp_postworld_user_meta where user_id=

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
select * from wp_postworld_user_meta where user_id=

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0,null,0,0,null,null,null,null,null,null,null)' at line 15]
INSERT INTO `wp_postworld_user_meta` (`user_id`, `post_points`, `post_points_meta`, `comment_points`, `share_points`, `share_points_meta`, `post_relationships`, `post_votes`, `comment_votes`, `location_city`, `location_region`, `location_country`) VALUES (,0,null,0,0,null,null,null,null,null,null,null);

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1]
update wp_postworld_user_meta set post_relationships='{"viewed":[],"favorites":[],"view_later":["86"]}' where user_id=
hmikhail commented 10 years ago

Yes you are right, due to renewing user_meta table schema, I forgot to change this part. Also in set_view_later, I forgot to add values for user_id and post_id if they were not sent as parameters.

ansonphong commented 10 years ago

Ok, glad you know the cause of it right away.

On Tuesday, October 29, 2013, hmikhail wrote:

Yes you are right, due to renewing user_meta table schema, I forgot to change this part. Also in set_view_later, I forgot to add values for user_id and post_id if they were not sent as parameters.

— Reply to this email directly or view it on GitHubhttps://github.com/phongmedia/postworld/issues/60#issuecomment-27290289 .

hmikhail commented 10 years ago

you can try it now