我没有脚本,但我有你可以使用的 mySQL。在此之前,我应该提到在 SQL 中存储 vCard 似乎有两种合乎逻辑的方法:
-
存储整个卡片并让数据库搜索(可能)巨大的文本字符串,并在代码的另一部分甚至客户端中处理它们。例如
如果不存在则创建表 vcards (
name_or_letter varchar(250) NOT NULL,
vcard text NOT NULL,
timestamp 时间戳默认 CURRENT_TIMESTAMP 更新 CURRENT_TIMESTAMP,
主键 (username)
) ENGINE=MyISAM 默认字符集=utf8 COLLATE=utf8_bin;
可能很容易实现,(取决于您对数据的处理方式)尽管如果您有很多条目,您的搜索将会很慢。
如果这仅适合您,那么这可能会起作用,(如果它有任何好处,那么它永远不会只适合您。)然后您可以使用一些漂亮的模块来处理 vCard 客户端或服务器端分享,(或与您分享的其他人。)
我见证了 vCard 的发展,并且知道将会有
将来 /some/ 时间会发生一些变化,所以我使用了三个表。
第一个是卡片,(这主要链接回我现有的表格 - 如果您不需要它,那么您的可以是精简版)。
第二个是卡定义(在 vCard 中似乎称为配置文件)。
最后是卡片的所有实际数据。
因为我让 DBIx::Class,(是的,我是其中之一)完成所有数据库的工作,(三个表)对我来说似乎工作得很好,
(尽管显然您可以收紧类型以更紧密地匹配rfc2426,
但在大多数情况下,每条数据只是一个文本字符串。)
我没有从这个人那里规范化地址的原因是我已经有一个
我数据库中的地址表,这三个仅用于非用户联系方式。
CREATE TABLE `vCards` (
`card_id` int(255) unsigned NOT NULL AUTO_INCREMENT,
`card_peid` int(255) DEFAULT NULL COMMENT 'link back to user table',
`card_acid` int(255) DEFAULT NULL COMMENT 'link back to account table',
`card_language` varchar(5) DEFAULT NULL COMMENT 'en en_GB',
`card_encoding` varchar(32) DEFAULT 'UTF-8' COMMENT 'why use anything else?',
`card_created` datetime NOT NULL,
`card_updated` datetime NOT NULL,
PRIMARY KEY (`card_id`) )
ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='These are the contact cards'
create table vCard_profile (
vcprofile_id int(255) unsigned auto_increment NOT NULL,
vcprofile_version enum('rfc2426') DEFAULT "rfc2426" COMMENT "defaults to vCard 3.0",
vcprofile_feature char(16) COMMENT "FN to CATEGORIES",
vcprofile_type enum('text','bin') DEFAULT "text" COMMENT "if it is too large for vcd_value then user vcd_bin",
PRIMARY KEY (`vcprofile_id`)
) COMMENT "These are the valid types of card entry";
INSERT INTO vCard_profile VALUES('','rfc2426','FN','text'),('','rfc2426','N','text'),('','rfc2426','NICKNAME','text'),('','rfc2426','PHOTO','bin'),('','rfc2426','BDAY','text'),('','rfc2426','ADR','text'),('','rfc2426','LABEL','text'),('','rfc2426','TEL','text'),('','rfc2426','EMAIL','text'),('','rfc2426','MAILER','text'),('','rfc2426','TZ','text'),('','rfc2426','GEO','text'),('','rfc2426','TITLE','text'),('','rfc2426','ROLE','text'),('','rfc2426','LOGO','bin'),('','rfc2426','AGENT','text'),('','rfc2426','ORG','text'),('','rfc2426','CATEGORIES','text'),('','rfc2426','NOTE','text'),('','rfc2426','PRODID','text'),('','rfc2426','REV','text'),('','rfc2426','SORT-STRING','text'),('','rfc2426','SOUND','bin'),('','rfc2426','UID','text'),('','rfc2426','URL','text'),('','rfc2426','VERSION','text'),('','rfc2426','CLASS','text'),('','rfc2426','KEY','bin');
create table vCard_data (
vcd_id int(255) unsigned auto_increment NOT NULL,
vcd_card_id int(255) NOT NULL,
vcd_profile_id int(255) NOT NULL,
vcd_prof_detail varchar(255) COMMENT "work,home,preferred,order for e.g. multiple email addresses",
vcd_value varchar(255),
vcd_bin blob COMMENT "for when varchar(255) is too small",
PRIMARY KEY (`vcd_id`)
) COMMENT "The actual vCard data";
这不是最好的 SQL,但我希望能有所帮助。