我试图编写我的第一个mySql存储过程并继续从服务器收到我无法理解的错误,希望有人能够帮我修复它。
我在做什么 我从社交网络收集一些参数,我需要将这些数据保存在两个不同的表中。我知道表模式可能不是最优的,但这是我目前无法改变的。
我的想法是从服务器端代码调用存储过程传入文章ID和一些其他参数,以及过程:
这是我写的存储过程
BEGIN
UPDATE
articles2
SET
fb_shares = n_shares,
fb_comments = n_comments,
fb_reactions = n_reactions,
tw_tweets = @tweets :=(tw_tweets + n_tweets),
tw_retweets = @retweets :=(tw_retweets + n_retweets),
tw_favorites = @favorites :=(tw_favorites + n_favorites),
tw_reach = @reach :=(tw_reach + n_reach),
tw_since_id = n_since_id,
popularity = @popularity :=(
(n_shares * fb_shares_weight) +(
n_comments * fb_comments_weight
) +(
n_reactions * fb_reactions_weight
) +(@tweets * tw_tweets_weight) +(@retweets * tw_retweets_weight) +(
@favorites * tw_favorites_weight
) +(@reach * tw_reach_weight)
),
popularity_updated =(popularity_updated + 1)
WHERE
id = n_id ;
INSERT
INTO
popularity(
article_id,
added,
popularity,
tw_tweets,
tw_reach,
tw_favorites,
tw_retweets,
tw_since_id,
fb_shares,
fb_comments,
fb_reactions
)
VALUES(
n_id,
NOW(), @popularity, @tweets, @reach, @favorites, @retweets, n_since_id, n_shares, n_comments, n_reactions) ;
END
我一直收到错误#1416 - Cannot get geometry object from data you send to the GEOMETRY field
并且从未执行过INSERT。我认为变量赋值是错误的,但无法理解如何修复它。
如上所述,我以前从未写过存储过程,因为那条线对我来说是正确的,我真的无法理解什么是错的。我不能排除我正在尝试做一些不应该用存储过程完成的事情,但是我在网上找到的几个例子让我觉得这应该是正确的......
提前谢谢你, 西蒙
编辑:
我摆脱了这个错误,但仍然没有执行INSERT
...这是更新的存储过程:
BEGIN
SET @tweets := 0, @retweets := 0, @favorites := 0, @reach := 0, @popularity := 0;
UPDATE
articles2
SET
fb_shares = n_shares,
fb_comments = n_comments,
fb_reactions = n_reactions,
tw_tweets = @tweets :=(tw_tweets + n_tweets),
tw_retweets = @retweets :=(tw_retweets + n_retweets),
tw_favorites = @favorites :=(tw_favorites + n_favorites),
tw_reach = @reach :=(tw_reach + n_reach),
tw_since_id = n_since_id,
popularity = @popularity :=(
(n_shares * fb_shares_weight) +(
n_comments * fb_comments_weight
) +(
n_reactions * fb_reactions_weight
) +(@tweets * tw_tweets_weight) +(@retweets * tw_retweets_weight) +(
@favorites * tw_favorites_weight
) +(@reach * tw_reach_weight)
),
popularity_updated =(popularity_updated + 1)
WHERE
id = n_id ;
SELECT @tweets, @retweets, @favorites, @reach, @popularity;
INSERT
INTO
popularity(
article_id,
added,
popularity,
tw_tweets,
tw_reach,
tw_favorites,
tw_retweets,
tw_since_id,
fb_shares,
fb_comments,
fb_reactions
)
VALUES(
n_id,
NOW(), @popularity, @tweets, @reach, @favorites, @retweets, n_since_id, n_shares, n_comments, n_reactions) ;
END
答案 0 :(得分:0)
检查popularity
表的定义,查找使用数据类型GEOMETRY定义的字段,并更改为适当的类型。