之前学习了[MFC中使用Access数据库](https://steemit.com/database/@oflyhigh/mfc-access),以及[MFC中向Access 数据库插入数据](https://steemit.com/database/@oflyhigh/5oc9jp-mfc-access),想着总要学以致用嘛,就打算把自己在STEEM区块链上的所有文章插入到数据库中。 ![](https://steemitimages.com/DQmRkLq6rRew3mHfx4vYGWyqpC8wSebLPeC2iZCXAdpuGkR/image.png) (图源 :[pixabay](https://pixabay.com/)) # 变长文本 原本以为应该是很简单的事情,先用Access建好数据表,然后从steem区块链读数据,再逐条插入即可。因为我关心的只有Title以及文章内容,所以只插入这些数据就好,为了方便定位到文章在steemit.com上的链接,我还插入了URL,当然了,还有文章的创建时间。 为了方便测试,先插入3、5条数据,插入很成功,然而为啥文章数据没插全呢?找了半天,才想起来我建表就是随便点点创建的,没做啥详细设置。一看body字段,我设置的是text类型,默认的长度限制255个字符,难怪被截短了。 因为文章长度很长,又不确定多长,所以我打算设置为变长类型,可是找了半天也没发现什么变长类型,只有一个Memo类型看起来貌似能满足需求。试着将字段类型改成Memo,果然OK了。搜了一下微软的相关网页:[The Memo data type is now called “Long Text”](https://support.office.com/en-us/article/The-Memo-data-type-is-now-called-Long-Text-dffe5e34-953e-4451-a05e-fba5d9b564b5),我这还是Memo应该是我Office版本太旧的缘故(2010)。 # 单引号替换 解决了文章内容被截短的问题,我又开始了插数据,这次使劲插吧。结果程序噼里啪啦的报错,尽管数据大部分都插入成功,但是丢了大概几十篇文章的样子。这让我有些不爽。调试了一下发现是文章内容中的**`'`**和SQL语句中的**`'`**冲突。大概类似这样: >`insert into posts(title) values('ddd'ddd')` Microsoft站点上找到一个和我问题类似的帖子,[SQL Statement to insert a single quote i.e., ' into a column of the into MSAccess table](https://social.msdn.microsoft.com/Forums/windows/en-US/fd03edf2-124f-4720-8987-0f477a9f5401/sql-statement-to-insert-a-single-quote-ie-into-a-column-of-the-into-msaccess-table),别人回复中给的解决方法是字符串替换大法。把**`'`**替换成**`''`**(两个单引号)。试着重新跑一遍程序,这次只少插入十几篇文章。 那里又出错了呢?让我再查查,晕,原来我有的帖子标题里也用到了**`'`**,真是郁闷,就不能好好的起标题,愉快地插数据吗?哎,继续我的替换大法,搞定之。 <center>![](https://steemitimages.com/DQmRx3oBr2RyQ3dnTgXBo1pm9GgQEeEy3PojzsyrEKmUE3D/image.png)</center> # 总结 说了这么多,其实就俩坑 * 变长文本用Memo类型(新版本变成Long Text)否则会被截短。 * 文本中的**`'`**要转义或者替换,否则和SQL语法冲突。 当然了,这两个坑或许有其它更好的解决方法,不过对我而言,好用就好啦,不去深究咯,回头大不了删库跑路。 # 相关链接 * [每天进步一点点:MFC中使用Access数据库](https://steemit.com/database/@oflyhigh/mfc-access) * [每天进步一点点:MFC中向Access 数据库插入数据](https://steemit.com/database/@oflyhigh/5oc9jp-mfc-access) * [The Memo data type is now called “Long Text”](https://support.office.com/en-us/article/The-Memo-data-type-is-now-called-Long-Text-dffe5e34-953e-4451-a05e-fba5d9b564b5) * [SQL Statement to insert a single quote i.e., ' into a column of the into MSAccess table](https://social.msdn.microsoft.com/Forums/windows/en-US/fd03edf2-124f-4720-8987-0f477a9f5401/sql-statement-to-insert-a-single-quote-ie-into-a-column-of-the-into-msaccess-table)
post_id | 48,685,436 |
---|---|
author | oflyhigh |
permlink | access |
category | database |
json_metadata | "{"links": ["https://steemit.com/database/@oflyhigh/mfc-access", "https://steemit.com/database/@oflyhigh/5oc9jp-mfc-access", "https://pixabay.com/", "https://support.office.com/en-us/article/The-Memo-data-type-is-now-called-Long-Text-dffe5e34-953e-4451-a05e-fba5d9b564b5", "https://social.msdn.microsoft.com/Forums/windows/en-US/fd03edf2-124f-4720-8987-0f477a9f5401/sql-statement-to-insert-a-single-quote-ie-into-a-column-of-the-into-msaccess-table"], "format": "markdown", "app": "steemit/0.1", "image": ["https://steemitimages.com/DQmRkLq6rRew3mHfx4vYGWyqpC8wSebLPeC2iZCXAdpuGkR/image.png"], "tags": ["database", "odbc", "mfc", "cn-programming", "cn"]}" |
created | 2018-05-15 15:42:24 |
last_update | 2018-05-15 15:42:24 |
depth | 0 |
children | 3 |
net_rshares | 20,797,203,294,672 |
last_payout | 2018-05-22 15:42:24 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 87.203 SBD |
curator_payout_value | 15.528 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 2,364 |
author_reputation | 1,148,153,621,496,884 |
root_title | 踩了Access数据库的两个坑,吐血中 |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
abit | 0 | 243,696,911,152 | 100% | ||
adm | 0 | 9,100,714,116,656 | 50% | ||
wongshiying | 0 | 119,952,232 | 100% | ||
blockchainbilly | 0 | 21,955,219,594 | 50% | ||
simon.braki.love | 0 | 3,731,537,364 | 100% | ||
deanliu | 0 | 1,109,405,344,128 | 100% | ||
laoyao | 0 | 32,990,861,745 | 100% | ||
somebody | 0 | 1,210,599,379,905 | 100% | ||
midnightoil | 0 | 121,227,174,454 | 100% | ||
xiaohui | 0 | 656,483,275,470 | 100% | ||
oflyhigh | 0 | 2,248,330,449,496 | 100% | ||
xiaokongcom | 0 | 8,286,766,306 | 100% | ||
yulan | 0 | 14,267,239,032 | 100% | ||
chinadaily | 0 | 234,676,363,629 | 100% | ||
helene | 0 | 613,883,604,350 | 100% | ||
ethansteem | 0 | 188,938,017,633 | 100% | ||
profitgenerator | 0 | 130,895,725 | 100% | ||
damarth | 0 | 703,255,090 | 3% | ||
jianghao | 0 | 231,676,028 | 10% | ||
mrtv2 | 0 | 56,605,725,711 | 100% | ||
steemtruth | 0 | 2,647,883,996 | 10% | ||
lalala | 0 | 81,063,419,647 | 100% | ||
devilwsy | 0 | 2,142,088,396 | 100% | ||
janiceting | 0 | 2,139,963,905 | 100% | ||
abraomarcos | 0 | 2,393,740,859 | 100% | ||
lydiachan | 0 | 21,818,029,173 | 100% | ||
newhope | 0 | 2,019,588,795,451 | 26% | ||
dragon40 | 0 | 1,895,951,352 | 10% | ||
blackbunny | 0 | 80,604,984,489 | 100% | ||
kouhei-gahaku | 0 | 9,779,913,778 | 50% | ||
chessmasterhex | 0 | 164,461,580 | 100% | ||
bxt | 0 | 162,965,387,085 | 100% | ||
lingfei | 0 | 48,956,466,198 | 100% | ||
yyyy | 0 | 424,874,350 | 100% | ||
alexis555 | 0 | 1,614,210,262,806 | 24% | ||
htooms | 0 | 82,574,059,996 | 35% | ||
austinsandersco | 0 | 758,068,096 | 70% | ||
kingofdew | 0 | 44,289,716,770 | 100% | ||
emcvay | 0 | 176,875,545 | 10% | ||
wylo | 0 | 613,964,238 | 100% | ||
jkkim | 0 | 60,586,510 | 10% | ||
ebejammin | 0 | 6,042,002,881 | 100% | ||
nanosesame | 0 | 39,901,387,908 | 30% | ||
cryptohustler | 0 | 30,706,609,866 | 100% | ||
exec | 0 | 77,842,311,872 | 100% | ||
eval | 0 | 747,674,210 | 100% | ||
michaelwilshaw | 0 | 6,974,669,853 | 10% | ||
speeding | 0 | 3,706,109,707 | 100% | ||
walkinharmony | 0 | 8,479,605,735 | 40% | ||
asterix87 | 0 | 13,616,223,281 | 100% | ||
canbethisone | 0 | 16,619,837,556 | 50% | ||
abetterworld | 0 | 2,935,462,568 | 100% | ||
raili | 0 | 9,583,524,543 | 100% | ||
that1consultant | 0 | 299,329,858 | 100% | ||
sanzo | 0 | 271,800,343 | 100% | ||
davaowhenyo | 0 | 614,503,785 | 100% | ||
allenshayzar | 0 | 614,503,785 | 100% | ||
raku | 0 | 613,122,478 | 100% | ||
resteeming | 0 | 610,787,288 | 100% | ||
ravenousappetite | 0 | 614,503,440 | 100% | ||
aabb | 0 | 10,871,619,102 | 100% | ||
auntigormint | 0 | 537,652,272 | 100% | ||
mrliga | 0 | 15,723,128,401 | 100% | ||
sweethoney | 0 | 253,884,794 | 100% | ||
liangfengyouren | 0 | 1,099,751,339 | 50% | ||
idx | 0 | 20,686,230,786 | 100% | ||
jiangchen | 0 | 9,448,174,962 | 100% | ||
lancy | 0 | 4,476,885,224 | 92% | ||
nainaztengra | 0 | 267,963,121,929 | 100% | ||
zellious | 0 | 5,766,154,750 | 100% | ||
bearpaw | 0 | 2,149,201,437 | 100% | ||
freedom-fighter | 0 | 614,503,785 | 100% | ||
technologynepal | 0 | 613,122,478 | 100% | ||
chenlocus | 0 | 1,067,209,002 | 40% | ||
davidke20 | 0 | 1,516,878,064 | 10% | ||
rosatravels | 0 | 37,775,458,110 | 20% | ||
dgorbunov | 0 | 512,900,618 | 100% | ||
khalilad | 0 | 611,243,358 | 100% | ||
ms8988 | 0 | 602,448,519 | 100% | ||
stakuza | 0 | 458,381,702 | 100% | ||
ikonik | 0 | 393,531,737 | 100% | ||
vfxness | 0 | 67,564,598 | 100% | ||
lemminon | 0 | 611,243,358 | 100% | ||
bobdos | 0 | 4,183,818,064 | 10% | ||
heyeshuang | 0 | 645,908,872 | 100% | ||
razor80 | 0 | 556,677,731 | 100% | ||
fastiduos | 0 | 611,243,358 | 100% | ||
winniex | 0 | 3,906,191,973 | 10% | ||
rebecca80 | 0 | 130,508,034 | 100% | ||
weavingwords | 0 | 53,934,697,502 | 100% | ||
nitro.live | 0 | 295,842,075 | 100% | ||
chaerin | 0 | 296,831,031 | 100% | ||
chann | 0 | 5,661,232,092 | 30% | ||
lebin | 0 | 31,430,557,549 | 30% | ||
coindzs | 0 | 126,634,330 | 100% | ||
saury | 0 | 303,723,844 | 100% | ||
patrickzhou | 0 | 10,944,182,268 | 100% | ||
ewq | 0 | 745,289,769 | 3% | ||
alimmudin | 0 | 518,991,836 | 100% | ||
maiyude | 0 | 8,884,246,810 | 10% | ||
benytg | 0 | 2,770,708,831 | 100% | ||
mycat | 0 | 127,133,695 | 12% | ||
historylover | 0 | 335,770,444 | 100% | ||
naijatimez | 0 | 259,001,292 | 100% | ||
btccurrency1 | 0 | 52,042,028 | 100% | ||
ethanlee | 0 | 10,942,975,323 | 100% | ||
amponchiek | 0 | 589,587,470 | 100% | ||
fishbb | 0 | 573,196,293 | 5% | ||
fanso | 0 | 1,206,401,166 | 100% | ||
taufik93 | 0 | 565,767,872 | 100% | ||
cryptoknight27 | 0 | 611,001,623 | 100% | ||
abss | 0 | 91,316,829 | 11% | ||
khayziljoy | 0 | 51,954,924 | 100% | ||
hepeng.chn | 0 | 146,635,515 | 100% | ||
fishdd | 0 | 540,758,915 | 5% | ||
pakhi | 0 | 599,460,810 | 100% | ||
liuzg | 0 | 149,459,507 | 100% | ||
hmayak | 0 | 302,225,010 | 100% | ||
sintina | 0 | 548,147,488 | 100% | ||
xiaoyuanwmm | 0 | 880,420,765 | 100% | ||
fabianugas | 0 | 315,109,057 | 100% | ||
bambugrove | 0 | 498,048,233 | 100% | ||
jessicali | 0 | 516,545,755 | 100% | ||
sitby | 0 | 491,527,487 | 100% |
神算用mfc会不会被码农 @coder-bts 鄙视
post_id | 48,686,815 |
---|---|
author | liuzg |
permlink | re-oflyhigh-access-20180515t155103060z |
category | database |
json_metadata | "{"app": "busy/2.4.0", "community": "busy", "tags": ["database"]}" |
created | 2018-05-15 15:51:03 |
last_update | 2018-05-15 15:51:03 |
depth | 1 |
children | 1 |
net_rshares | 46,841,068,726 |
last_payout | 2018-05-22 15:51:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.173 SBD |
curator_payout_value | 0.057 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 26 |
author_reputation | 499,906,621,111,017 |
root_title | 踩了Access数据库的两个坑,吐血中 |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
oflyhigh | 0 | 46,841,068,726 | 2% |
鄙视啊鄙视啊,就习惯了
post_id | 48,737,176 |
---|---|
author | oflyhigh |
permlink | re-liuzg-re-oflyhigh-access-20180515t231358434z |
category | database |
json_metadata | "{"app": "steemit/0.1", "tags": ["database"]}" |
created | 2018-05-15 23:14:03 |
last_update | 2018-05-15 23:14:03 |
depth | 2 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-05-22 23:14:03 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 11 |
author_reputation | 1,148,153,621,496,884 |
root_title | 踩了Access数据库的两个坑,吐血中 |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
别呀,才开始就想着 > 回头大不了删库跑路 继续继续…………
post_id | 48,749,817 |
---|---|
author | shine.wong |
permlink | re-oflyhigh-access-20180516t012524038z |
category | database |
json_metadata | "{"tags": ["database"], "app": "steemit/0.1"}" |
created | 2018-05-16 01:25:33 |
last_update | 2018-05-16 01:25:33 |
depth | 1 |
children | 0 |
net_rshares | 0 |
last_payout | 2018-05-23 01:25:33 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.000 SBD |
curator_payout_value | 0.000 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 31 |
author_reputation | 1,373,339,077,399 |
root_title | 踩了Access数据库的两个坑,吐血中 |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |