Python-Ref > Databases and Python > Python and SQLite > SQLite basics
 
 

^^
Moduly
Knihovní funkce

SQLite basics

SQLite is lean implementation of SQL database that does not require a server and stores all its data in one file. It is an ideal solution for distribution of databases to client computers, even though it is less suitable for huge mutli-user databases.
The following code shows how to create a SQLite database and populate it with some data. The code is very similar to what we would do in MySQL, showing only a few differences between the SQLite and MySQL Python API.
The most important fact is that in MySQL autocommit is the default setting, while in SQLite you have to commit every change to the data if you want to save it. (This can sometimes be used to get much better speed in SQLite, by commiting inteligently in chunks of 100 or so inserts, rather than after every single one.)
Expand/Shrink
7	MUIPLRMGAXZWSQ-FSHFIPFOCP	CCN1C=NC2=C1N=CN=C2N	9-ethylpurin-6-amine
11	WSLDOOZREJYCGB-UHFFFAOYAL	C(CCl)Cl	1,2-dichloroethane
12	RDJUHLUBPADHNP-UHFFFAOYAO	C1=C(C=C(C(=C1O)O)O)O	benzene-1,2,3,5-tetrol
13	PBKONEOXTCPAFI-UHFFFAOYAE	C1=CC(=C(C=C1Cl)Cl)Cl	1,2,4-trichlorobenzene
19	GLDQAMYCGOIJDV-KZFATGLACE	C1=CC(=C(C(=C1)O)O)C(=O)O	2,3-dihydroxybenzoic acid
33	QSKPIOLLBIHNAC-UHFFFAOYAP	C(C=O)Cl	2-chloroacetaldehyde
34	SZIFAVKTNFCBPC-UHFFFAOYAF	C(CCl)O	2-chloroethanol
43	HWXBTNAVRSUOJR-AUDIXQRPCC	C(CC(=O)O)C(C(=O)O)O	2-hydroxypentanedioic acid
44	ROBFUDYVXSDBQM-SNMYEHAQCX	C(C(=O)[O-])(C(=O)[O-])O	2-hydroxypropanedioate
45	ROBFUDYVXSDBQM-AOTPWWKUCB	C(C(=O)O)(C(=O)O)O	2-hydroxypropanedioic acid
51	KPGXRSRHYNQIFN-AUDIXQRPCH	C(CC(=O)O)C(=O)C(=O)O	2-oxopentanedioic acid
58	TYEYBOSBBBHJIV-BRMMOCHJCF	CCC(=O)C(=O)O	2-oxobutanoic acid
63	PCEJMSIIDXUDSN-FZOZFQFYCY	CC(CC(C(=O)O)N)N	2,4-diaminopentanoic acid
66	RANCECPPZPIPNO-UHFFFAOYAZ	C1=CC(=C(C=C1Cl)O)Cl	2,5-dichlorophenol
71	FGSBNBBHOZHUBO-PSPNOWEWCB	C(CC(=O)C(=O)O)CC(=O)O	2-oxohexanedioic acid
72	YQUVCSBJEUQKSH-KZFATGLACZ	C1=CC(=C(C=C1C(=O)O)O)O	3,4-dihydroxybenzoic acid
75	PCXDJQZLDDHMGX-UHFFFAOYAJ	C(CN)C=O	3-aminopropanal
79	GZPHSAQLYPIAIN-UHFFFAOYAR	C1=CC(=CN=C1)C#N	pyridine-3-carbonitrile
93	RTGHRDFWYQHVFW-PSPNOWEWCT	C(CC(=O)O)C(=O)CC(=O)O	3-oxohexanedioic acid
96	WDJHALXBUFZDSR-BRMMOCHJCT	CC(=O)CC(=O)O	3-oxobutanoic acid
101	IAVREABSGIHHMO-UHFFFAOYAC	C1=CC(=CC(=C1)O)C=O	3-hydroxybenzaldehyde
102	OKVJCVWFVRATSG-UHFFFAOYAA	C1=CC(=CC(=C1)O)CO	3-(hydroxymethyl)phenol
107	XMIIGOLPHOKFCH-KZFATGLACR	C1=CC=C(C=C1)CCC(=O)O	3-phenylpropanoic acid
108	WGNUNYPERJMVRM-BGGKNDAXCI	C1=CC(=CN=C1)CC(=O)O	2-pyridin-3-ylacetic acid
118	DZQLQEYLEYWJIB-UHFFFAOYAT	C(CC=O)CN	4-aminobutanal
119	BTCSSZJGUNDROE-BRMMOCHJCO	C(CC(=O)O)CN	4-aminobutanoic acid
125	BVJSUAQZOZWCKN-UHFFFAOYAV	C1=CC(=CC=C1CO)O	4-(hydroxymethyl)phenol
126	RGHHSNMVTDWUBI-UHFFFAOYAN	C1=CC(=CC=C1C=O)O	4-hydroxybenzaldehyde
129	JGEGJYXHCFUMJF-UHFFFAOYAU	CC(C)CCC=O	4-methylpentanal
135	FJKROLUGYXJWQN-BGGKNDAXCM	C1=CC(=CC=C1C(=O)O)O	4-hydroxybenzoic acid
138	JJMDCOVWQOJGCB-QDQILVOLCV	C(CCN)CC(=O)O	5-aminopentanoic acid
167	KVDQMARGGBLIJM-UHFFFAOYAN	C1CN=C2C(=N1)C=NC=N2	6,7-dihydropteridine
173	GUAHPAJOXVYFON-XWKXFZRBCC	CC(C(=O)CCCCCC(=O)O)N	8-amino-7-oxononanoic acid
174	LYCAIKOWRPUZTN-UHFFFAOYAD	C(CO)O	ethane-1,2-diol
175	QTBSBXVTEAMEQO-KSORUIRRCC	CC(=O)[O-]	acetate
176	QTBSBXVTEAMEQO-TULZNQERCK	CC(=O)O	acetic acid
177	IKHGUXGNUITLKF-UHFFFAOYAB	CC=O	acetaldehyde
178	DLFVBJFMPXGRIB-ZZOWFUDICC	CC(=O)N	acetamide
179	ROWKJAVDOGWPAT-UHFFFAOYAD	CC(C(=O)C)O	3-hydroxybutan-2-one
180	CSCPPACGZOOCGX-UHFFFAOYAF	CC(=O)C	propan-2-one
186	LIPOUNRJVLNBCD-NUMVZRSTCM	CC(=O)OP(=O)(O)O	phosphono acetate
190	GFFGJBXGBJISGV-KOOMONESCC	C1=NC2=C(N1)C(=NC=N2)N	7H-purin-6-amine
196	WNLRTRBMVRJNCN-AUDIXQRPCS	C(CCC(=O)O)CC(=O)O	hexanedioic acid
199	QYPPJABKJHAVHS-UNXFWZPKCC	C(CCN=C(N)N)CN	2-(4-aminobutyl)guanidine
207	GFXYTQPNNXGICT-BGGKNDAXCZ	C(CC=O)CC(C(=O)O)N	2-amino-6-oxohexanoic acid
215	BCDGQXUMWHRQCB-UHFFFAOYAB	CC(=O)CN	1-aminopropan-2-one
219	SAUCHDKDCUROAO-QDQILVOLCN	CC(=O)C(C(=O)O)N	2-amino-3-oxobutanoic acid
222	QGZKDVFQNNGYKY-UHFFFAOYAF	N	azane
223	QGZKDVFQNNGYKY-YMUWUXIECQ	[NH4+]	azanium
226	FBVWYYILRHVALZ-UHFFFAOYAC	C(N)(O)P	amino-phosphanylmethanol
227	RWZYAGGXGHYGMB-BGGKNDAXCO	C1=CC=C(C(=C1)C(=O)O)N	2-aminobenzoic acid
229	SRBFZHDQGSBBOR-UHFFFAOYAW	C1C(C(C(C(O1)O)O)O)O	oxane-2,3,4,5-tetrol
233	DJHGAFSJWGLOIV-ZBNSPISCCM	O[As](=O)([O-])[O-]	hydrogen arsorate
234	DJHGAFSJWGLOIV-AHTNDGLTCQ	O[As](=O)(O)O	arsoric acid
239	UCMIRNVEIXFBKS-JSWHHWTPCS	C(CN)C(=O)O	3-aminopropanoic acid
240	HUMNYLRZRPPJDN-UHFFFAOYAE	C1=CC=C(C=C1)C=O	benzaldehyde
241	UHOVQNZJYSORNB-UHFFFAOYAH	C1=CC=CC=C1	benzene
242	WPYMKLBDIGXBTP-UJYIWYDQCH	C1=CC=C(C=C1)C(=O)[O-]	benzoate
243	WPYMKLBDIGXBTP-FZOZFQFYCI	C1=CC=C(C=C1)C(=O)O	benzoic acid
244	WVDDGKGOMKODPV-UHFFFAOYAH	C1=CC=C(C=C1)CO	phenylmethanol
254	YKOQAAJBYBTSBS-UHFFFAOYAC	C1=CC=C(C=C1)C2=C(C(=CC=C2)O)O	3-phenylbenzene-1,2-diol
259	CPELXLSAUQHCOX-ZMJNGJBWCE	[Br-]	bromide
260	CPELXLSAUQHCOX-UHFFFAOYAZ	Br	hydrogen bromide
261	ZTQSAGDEMFDKMZ-UHFFFAOYAZ	CCCC=O	butanal
262	OWBTYPJTUOEWEK-UHFFFAOYAE	CC(C(C)O)O	butane-2,3-diol
263	LRHPLDYGYMQRHN-UHFFFAOYAS	CCCCO	butan-1-ol
264	FERIUCNNQQJTOY-JSWHHWTPCW	CCCC(=O)O	butanoic acid
266	JSHMCUNOMIZJDJ-ZDKSUBDRCB	CCCC(=O)OP(=O)(O)O	phosphono butanoate
271	BHPQYMZQTOCNFJ-UHFFFAOYAP	[Ca+2]	calcium(+2) cation
273	VHRGRCVQAFMJIZ-UHFFFAOYAX	C(CCN)CCN	pentane-1,5-diamine
276	KXDHJXZQYSOELW-GLLOPPQGCQ	C(=O)(N)[O-]	carbamate
277	KXDHJXZQYSOELW-TULZNQERCV	C(=O)(N)O	carbamic acid
278	FFQKYPRQEYGKAF-HUFPXAKNCL	C(=O)(N)OP(=O)(O)O	phosphono carbamate
280	CURLTUGMZLYLDI-UHFFFAOYAO	C(=O)=O	carbon dioxide
281	UGFAIRIUMAVXCW-UHFFFAOYAT	[C-]#[O+]	carbon monoxide
283	BDAGIHXWWSANSR-ASVDBMMWCU	C(=O)[O-]	formate
284	BDAGIHXWWSANSR-QEZKKOIZCL	C(=O)O	formic acid
285	NQRKYASMKDDGHT-ZURMFFRACM	C(C(=O)[O-])ON	2-aminooxyacetate
286	NQRKYASMKDDGHT-JLSKMEETCS	C(C(=O)O)ON	2-aminooxyacetic acid
289	YCIMNLLNPGFGHC-UHFFFAOYAA	C1=CC=C(C(=C1)O)O	benzene-1,2-diol
297	VNWKTOKETHGBQD-UHFFFAOYAM	C	methane
300	FOCAUTSVDIKZOP-JLSKMEETCI	C(C(=O)O)Cl	2-chloroacetic acid
301	AJPXTSMULZANCB-UHFFFAOYAV	C1=CC(=C(C=C1O)Cl)O	2-chlorobenzene-1,4-diol
307	KJPRLNWUNMBNBZ-UHFFFAOYAB	C1=CC=C(C=C1)C=CC=O	3-phenylprop-2-enal
308	OOCCDEMITAIZTP-UHFFFAOYAA	C1=CC=C(C=C1)C=CCO	3-phenylprop-2-en-1-ol
310	TXXHDPDFNKHHGW-AUDIXQRPCS	C(=CC(=O)O)C=CC(=O)O	hexa-2,4-dienedioic acid
312	VEXZGXHMUGYJMC-QOKNLKRHCF	[Cl-]	chloride
313	VEXZGXHMUGYJMC-UHFFFAOYAT	Cl	hydrogen chloride
323	ZYGHJZDHTFUPRJ-UHFFFAOYAC	C1=CC=C2C(=C1)C=CC(=O)O2	chromen-2-one
326	WTWBUQJHJGUZCY-UHFFFAOYAP	CC(C)C1=CC=C(C=C1)C=O	4-propan-2-ylbenzaldehyde
331	NGDLSXMSQYUVSJ-BGGKNDAXCN	CC(CC(CC(=O)O)N)N	3,5-diaminohexanoic acid
332	YOMSJEATGXXYPX-UHFFFAOYAD	COC1=C(C=CC(=C1)C=C)O	4-ethenyl-2-methoxyphenol
335	QWVGKYWNOKOFNN-UHFFFAOYAS	CC1=CC=CC=C1O	2-methylphenol
338	YGSDEFSMJLZEOE-BGGKNDAXCM	C1=CC=C(C(=C1)C(=O)O)O	2-hydroxybenzoic acid
340	PGSWEKYNAOWQDF-UHFFFAOYAB	CC1=C(C(=CC=C1)O)O	3-methylbenzene-1,2-diol
342	RLSSMJSEOOYNOY-UHFFFAOYAJ	CC1=CC(=CC=C1)O	3-methylphenol
354	HYVSZVZMTYIHKF-FLKJISBTCS	C(CC(=O)O)C=CC(=O)C(=O)O	2-oxohept-3-enedioic acid
356	TVMXDCGIABBOFY-UHFFFAOYAY	CCCCCCCC	octane
358	FAASBXNEOGMQHS-BGGKNDAXCC	CC(CC(=O)CC(=O)O)N	5-amino-3-oxohexanoic acid
359	QCDYQQDYXPDABM-UHFFFAOYAF	C1=C(C=C(C=C1O)O)O	benzene-1,3,5-triol
363	LYIIBVSRGJSHAV-UHFFFAOYAY	C(C=O)N	2-aminoacetaldehyde
364	PECYZEOJVXMISF-BRMMOCHJCT	C(C(C(=O)O)N)N	2,3-diaminopropanoic acid
371	YTIVTFGABIZHHX-AOTPWWKUCY	C(#CC(=O)O)C(=O)O	but-2-ynedioic acid
379	WWZKQHOCKIZLMA-BGGKNDAXCD	CCCCCCCC(=O)O	octanoic acid
385	WLJVNTCWHIRURA-PSPNOWEWCY	C(CCC(=O)O)CCC(=O)O	heptanedioic acid
389	AHLPHDHHMVZTML-FZOZFQFYCX	C(CC(C(=O)O)N)CN	2,5-diaminopentanoic acid
392	QKEWQOJCHPFEAF-BGGKNDAXCY	C(CC(CC(=O)O)N)CN	3,6-diaminohexanoic acid
397	ZOAMBXDOGPRZLP-QMLCPYSLCD	C1=CC=C2C(=C1)C(=CN2)CC(=O)N	2-(1H-indol-3-yl)acetamide
398	FGLBSLMDCBOPQK-UHFFFAOYAM	CC(C)[N+](=O)[O-]	2-nitropropane
402	RWSOTUBLDIXVET-UHFFFAOYAJ	S	hydrogen sulfide
403	PLIKAWJENQZMHA-UHFFFAOYAD	C1=CC(=CC=C1N)O	4-aminophenol
412	MYKUKUCHPMASKF-UHFFFAOYAS	C1CC(NC1)C2=CN=CC=C2	3-pyrrolidin-2-ylpyridine
419	SOXXPQLIZIPMIZ-PSPNOWEWCB	C(C(=O)C=CC(=O)O)C(=O)O	4-oxohex-2-enedioic acid
424	CKLJMWTZIZZHCS-HJYFZBQUCZ	C(C(C(=O)O)N)C(=O)O	2-aminobutanedioic acid
428	XFNJVJPLKCPIBV-UHFFFAOYAG	C(CN)CN	propane-1,3-diamine
441	WHBMMWSBFZVSSR-BRMMOCHJCA	CC(CC(=O)O)O	3-hydroxybutanoic acid
447	LULAYUGMBFYYEX-BGGKNDAXCG	C1=CC(=CC(=C1)Cl)C(=O)O	3-chlorobenzoic acid
453	FBPFZTCFMRRESA-UHFFFAOYAI	C(C(C(C(C(CO)O)O)O)O)O	hexane-1,2,3,4,5,6-hexol
454	NUJGJRNETVAIRJ-UHFFFAOYAK	CCCCCCCC=O	octanal
460	LHGVFZTZFXWLCP-UHFFFAOYAI	COC1=CC=CC=C1O	2-methoxyphenol
469	OYIFNHCXNCRBQI-PSPNOWEWCJ	C(CC(C(=O)O)N)CC(=O)O	2-aminohexanedioic acid
470	OGNSCSPNOLGXSM-QDQILVOLCY	C(CN)C(C(=O)O)N	2,4-diaminobutanoic acid
484	QRZMXADUXZADTF-BRMMOCHJCQ	C1=C(NC=N1)N	3H-imidazol-4-amine
487	ZIYVHBGGAOATLY-AOTPWWKUCR	CC(C(=O)O)C(=O)O	2-methylpropanedioic acid
490	YEMKIGUKNDOZEG-NUMVZRSTCF	C(C=O)P(=O)(O)O	2-oxoethylphosphonic acid
502	YANFYYGANIYHGI-XLKFYZMLCW	C(CCNC(=O)N)CN	4-aminobutylurea
504	CAAMSDWKXXPUJR-JSWHHWTPCC	C1C(=O)NC=N1	3,5-dihydroimidazol-4-one
523	VHKNBDIQDAXGBL-FZOZFQFYCD	C(CC(=O)C(=O)O)C=O	2,5-dioxopentanoic acid
525	BJEPYKJPYRNKOW-HJYFZBQUCH	C(C(C(=O)O)O)C(=O)O	2-hydroxybutanedioic acid
527	NBBJYMSMWIIQGU-UHFFFAOYAZ	CCC=O	propanal
529	ASCFNMCAHFUBCO-VDBCHIHOCB	C(C(=O)O)OP(=O)(O)O	2-phosphonooxyacetic acid
533	SPVXKVOXSXTJOY-UHFFFAOYAF	[SeH2]	hydrogen selenide
540	XLJMAIOERFSOGZ-UHFFFAOYAT	C(#N)O	cyanic acid
541	BXRFQSNOROATLV-UHFFFAOYAO	C1=CC(=CC=C1C=O)[N+](=O)[O-]	4-nitrobenzaldehyde
545	GCPXMJHSNVMWNM-UHFFFAOYAA	O[As](O)O	arsorous acid
546	XUYJLQHKOGNDPB-VDBCHIHOCO	C(C(=O)O)P(=O)(O)O	2-phosphonoacetic acid
559	VCOFTLCIPLEZKE-PPMNOVJICR	C(CC=O)CN=C(N)N	2-(4-oxobutyl)guanidine
564	SLXKOJJOQWFEFD-FZOZFQFYCD	C(CCC(=O)O)CCN	6-aminohexanoic acid
567	DCNLOVYDMCVNRZ-GJDLCBJWAH	C1=CC=C(C=C1)[Hg]	phenylmercury
568	TXCDCPKCNAJMEE-UHFFFAOYAX	C1=CC=C2C(=C1)C3=CC=CC=C3O2	dibenzofuran
597	OPTASPLRGRRNAP-PTAWIYCUCW	C1=C(NC(=O)N=C1)N	4-amino-3H-pyrimidin-2-one
602	QNAYBMKLOCPYGJ-JSWHHWTPCH	CC(C(=O)O)N	2-aminopropanoic acid
611	WHUUTDBJXJRKMK-AUDIXQRPCX	C(CC(=O)O)C(C(=O)O)N	2-aminopentanedioic acid
612	JVTAAEKCZFNVCJ-JSWHHWTPCE	CC(C(=O)O)O	2-hydroxypropanoic acid
649	OIVLITBTBDPEFK-JYEHRPOACO	C1CNC(=O)NC1=O	1,3-diazinane-2,4-dione
650	QSJXEFYPDANLFS-UHFFFAOYAX	CC(=O)C(=O)C	butane-2,3-dione
652	KCEGBPIYGIWCDH-XWKXFZRBCL	CC(C(CCCCCC(=O)O)N)N	7,8-diaminononanoic acid
654	UCQFCFPECQILOL-JSWHHWTPCF	CCOP(=O)(O)OCC	diethyl hydrogen phosphate
660	VMUXSMXIQBNMGZ-UHFFFAOYAH	C1CC(=O)OC2=CC=CC=C21	chroman-2-one
663	VLYUGYAKYZETRF-JSGPKCTECC	C(CCC(=O)N)CC(CCS)S	6,8-bis-sulfanyloctanamide
670	RXKJFZQQPQGTFL-UHFFFAOYAE	C(C(=O)CO)O	1,3-dihydroxypropan-2-one
673	FFDGPVCHZBVARC-BRMMOCHJCJ	CN(C)CC(=O)O	2-dimethylaminoacetic acid
674	ROSDSFDQCJNGOL-UHFFFAOYAM	CNC	N-methylmethanamine
679	IAZDPXIOMUYVGZ-UHFFFAOYAR	CS(=O)C	methylsulfinylmethane
700	HZAXFHJVJLSVMW-UHFFFAOYAD	C(CO)N	2-aminoethanol
702	LFQSCWFLJHTTHZ-UHFFFAOYAB	CCO	ethanol
712	WSFSSNUMVMOOMR-UHFFFAOYAT	C=O	formaldehyde
713	ZHNUHDYFZUAESO-RZDQGJFACD	C(=O)N	formamide
723	VZCYOOQTPOCHFL-AOTPWWKUCS	C(=CC(=O)O)C(=O)O	but-2-enedioic acid
743	JFCQEDHGNNZCLN-HJYFZBQUCP	C(CC(=O)O)CC(=O)O	pentanedioic acid
750	DHMQDGOQFOQNFH-JLSKMEETCN	C(C(=O)O)N	2-aminoacetic acid
751	MNQZXJOMYWMBOU-UHFFFAOYAU	C(C(C=O)O)O	2,3-dihydroxypropanal
753	PEDCQBHIVMGVHV-UHFFFAOYAF	C(C(CO)O)O	propane-1,2,3-triol
756	WGCNASOHLSPBMP-UHFFFAOYAH	C(C=O)O	2-hydroxyacetaldehyde
757	AEMRFAOFKBGASW-JLSKMEETCI	C(C(=O)O)O	2-hydroxyacetic acid
760	HHLFWLYXYJOTON-JLSKMEETCL	C(=O)C(=O)O	oxaldehydic acid
767	BVKZGUZCCUSVTD-IBIRENAJCI	C(=O)(O)O	carbonic acid
768	LELOWRISYMNNSU-UHFFFAOYAU	C#N	formonitrile
769	BVKZGUZCCUSVTD-JCBUHNHRCY	C(=O)(O)[O-]	hydrogen carbonate
781	ZMZDMBWJUHKJPS-UHFFFAOYAD	C(#N)S	thiocyanic acid
783	UFHFLCQGNIYNRP-UHFFFAOYAN	[HH]	molecular hydrogen
784	MHAJPDPJQMAIIY-UHFFFAOYAL	OO	hydrogen peroxide
785	QIGBRXMKCJKVMJ-UHFFFAOYAX	C1=CC(=CC=C1O)O	benzene-1,4-diol
787	AVXURJPOCDRRFD-UHFFFAOYAD	NO	hydroxylamine
790	FDGQSTZJBFJUBT-HJYFZBQUCE	C1=NC2=C(N1)C(=O)N=CN2	3,7-dihydropurin-6-one
795	RAXXELZNTBOGNW-JLSKMEETCJ	C1=CN=CN1	1H-imidazole
796	NMUOATVLLQEYHI-FHORRWOCDS	C(C(=N)C(=O)O)C(=O)O	2-iminobutanedioic acid
798	SIKJAQJRHWYJAI-UHFFFAOYAI	C1=CC=C2C(=C1)C=CN2	1H-indole
801	SEOVTRFCIGRIMH-TWWDDUKDCL	C1=CC=C2C(=C1)C(=CN2)CC(=O)[O-]	2-(1H-indol-3-yl)acetate
807	PNDPGZBMCMUPRI-UHFFFAOYAF	II	molecular iodine
813	NPYPAHLBTDXSSS-UHFFFAOYAE	[K+]	potassium(+1) cation
824	SNDPXSYFESPGGJ-QDQILVOLCO	CCCC(C(=O)O)N	2-aminopentanoic acid
827	HEBKCHPVOIAQTA-UHFFFAOYAB	C(C(C(C(CO)O)O)O)O	pentane-1,2,3,4,5-pentol
829	HOSWPDPVFBCLSY-QDQILVOLCR	C(C=O)C(C(=O)O)N	2-amino-4-oxobutanoic acid
855	BSABBBMNWQWLLU-UHFFFAOYAY	CC(C=O)O	2-hydroxypropanal
866	KDXKERNSBIXSRK-BGGKNDAXCU	C(CCN)CC(C(=O)O)N	2,6-diaminohexanoic acid
867	OFOBLEOULBTSOW-CVXXDPDJCU	C(C(=O)O)C(=O)O	propanedioic acid
868	OAKURXIZZOAYBC-JSWHHWTPCF	C(C=O)C(=O)O	3-oxopropanoic acid
878	LSDPWZHWYPCBBB-UHFFFAOYAW	CS	methanethiol
880	AIJULSRZWUXGPQ-UHFFFAOYAZ	CC(=O)C=O	2-oxopropanal
881	LGRLWUINFJPLSH-UHFFFAOYAK	[CH3-]	carbanide
887	OKKJLVBELUTLKV-UHFFFAOYAX	CO	methanol
888	JLVVSXFLKOJNIY-UHFFFAOYAC	[Mg+2]	magnesium(+2) cation
904	FZERHIULMFGESH-BGGKNDAXCW	CC(=O)NC1=CC=CC=C1	N-phenylacetamide
923	FKNQFGJONOIPTF-UHFFFAOYAZ	[Na+]	sodium(+1) cation
931	UFWIBTONFRDIAS-UHFFFAOYAC	C1=CC=C2C=CC=CC2=C1	naphthalene
933	RBLWMQWAHONKNC-UHFFFAOYAH	[NH3+]O	hydroxyazanium
934	VEQPNABPJHWNSG-UHFFFAOYAL	[Ni+2]	nickel(+2) cation
935	PXHVJJICTQNCMI-UHFFFAOYAH	[Ni]	nickel
936	DFPAKSUCGFBDDF-IAUQMDSZCD	C1=CC(=CN=C1)C(=O)N	pyridine-3-carboxamide
Zdroj: (sqlite1-1.py)
  1   from pysqlite2 import dbapi2 as sqlite
  2   
  3   # connect to a database, a file will be created if it does not exist
  4   connection = sqlite.connect( "structures.db")
  5   # obtain a cursor
  6   cursor = connection.cursor()
  7   # clean the database if it already exists
  8   cursor.execute( "DROP TABLE IF EXISTS structures;")
  9   # create table
 10   cursor.execute( """CREATE TABLE structures (
 11     id INTEGER PRIMARY KEY,
 12     name TEXT,
 13     inchikey TEXT,
 14     smiles TEXT);""")
 15   connection.commit()
 16   
 17   # population of the database
 18   f = file( "structures.200.txt")
 19   for line in f:
 20     id, inchikey, smiles, name = line.strip().split("\t")
 21     cursor.execute( "INSERT INTO structures (id,name,inchikey,smiles) VALUES (?,?,?,?);", (id, name, inchikey, smiles))
 22   connection.commit() # commit is not required after each execute
 23   
 24   cursor.close()
 25   connection.close()
Doba běhu: 34.4 ms
The following code shows a simple select on the database we just created in the example above.
Expand/Shrink
Zdroj: (sqlite1-2.py)
  1   from pysqlite2 import dbapi2 as sqlite
  2   
  3   # connect to a database, a file will be created if it does not exist
  4   connection = sqlite.connect( "structures.db")
  5   # obtain a cursor
  6   cursor = connection.cursor()
  7   # search the database
  8   cursor.execute( "SELECT id,name FROM structures WHERE name LIKE '%benzene%';")
  9   # cursor behaves as list of results when we try to iterate over it
 10   for id, name in cursor:
 11     print "%-30s %s" % (name, "http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=%d"%id)
 12   
 13   cursor.close()
 14   connection.close()
stdout:
benzene-1,2,3,5-tetrol         http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=12
1,2,4-trichlorobenzene         http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=13
benzene                        http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=241
3-phenylbenzene-1,2-diol       http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=254
benzene-1,2-diol               http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=289
2-chlorobenzene-1,4-diol       http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=301
3-methylbenzene-1,2-diol       http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=340
benzene-1,3,5-triol            http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=359
benzene-1,4-diol               http://pubchem.ncbi.nlm.nih.gov/summary/summary.cgi?cid=785
Doba běhu: 38.4 ms