¾È±Ô °øºÎ¹æ

Python ÇÁ·Î±×·¡¹Ö > Sqlite3 - ´Ù¾çÇÑ Äõ¸® ¿¹Á¦µé

µî·ÏÀÏ : 2017-08-04 14:01 Á¶È¸¼ö : 53,034

1. Å×À̺íÀÇ Çʵå¸í ±¸Çϱâ ( cursor.description )
     Å×À̺íÀÇ Çʵå¸íÀ» ±¸Çϱâ À§Çؼ­´Â cursor.description À» »ç¿ëÇÏ¸é µÈ´Ù.
 
cursor.execute("select * from suspect5")

for row in cursor.description:
    print(row[0])


°á°ú
---------------------------
Name
price

Çʵå¸í, Name, price Çʵå¸íÀÌ Ãâ·ÂµÇ´Â°É È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.

2. DB ³»ÀÇ Å×ÀÌºí ¸ñ·ÏÀ» ±¸ÇÏÀÚ
     select name from sqlite_master where type='table'
   cursor.execute("select name from sqlite_master where type='table'")
    rows = cursor.fetchall()

    for row in rows:
        print(row[0])

¿¹Á¦¸¦ È®ÀÎÇØ º¸±â ¹Ù¶ø´Ï´Ù.

3. DB ³»¿¡ ƯÁ¤ Å×À̺íÀÌ Á¸ÀçÇÏ´ÂÁö ¾Ë¾Æº¸ÀÚ.
     select name from sqlite_master where type='table' and name='Å×À̺í¸í'
   cursor.execute("select name from sqlite_master where type='table' and name='Å×À̺í¸í'")
    rows = cursor.fetchall()

    for row in rows:
        print(row[0])

°á°ú: Å×À̺íÀÌ Á¸ÀçÇϸé: [('Å×À̺í¸í',)]
     Á¸ÀçÇÏÁö ¾ÊÀ¸¸é : []

4. Å×ÀÌºí³»ÀÇ Çʵå(column) Type ¾Ë¾Æ³»±â
    PRAGMA table_info(Å×À̺í¸í)
    cursor.execute("PRAGMA table_info(suspect5)")
    rows = cursor.fetchall()

    for row in rows:
        print(row)
°á°ú : (0, 'Name', 'text', 0, None, 0)
(1, 'price', 'int', 0, None, 0)

°á°ú





 
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.