बस मेरे जैसे सुपर noobs के लिए सोच रहा है कि कैसे या क्या लोगों का मतलब
PRAGMA table_info('table_name')
आप नीचे दिखाए गए अनुसार अपने तैयार कथन के रूप में उपयोग का उपयोग करना चाहते हैं। ऐसा करने से ऐसी तालिका दिखाई देती है जो इस तरह दिखती है, सिवाय इसके कि आपकी तालिका से संबंधित मूल्यों के साथ पॉप्युलेट किया गया हो।
cid name type notnull dflt_value pk
---------- ---------- ---------- ---------- ---------- ----------
0 id integer 99 1
1 name 0 0
जहां आईडी और नाम आपके कॉलम के वास्तविक नाम हैं।
//returns the name
sqlite3_column_text(stmt, 1);
//returns the type
sqlite3_column_text(stmt, 2);
कौन सा वर्तमान पंक्ति के स्तंभ का नाम वापस आ जाएगी: ताकि मूल्य आप का उपयोग करके स्तंभ नाम का चयन करने की जरूरत है पाने के लिए। उन सभी को पकड़ने के लिए या जो आप चाहते हैं उसे ढूंढने के लिए आपको सभी पंक्तियों के माध्यम से फिर से भरना होगा। ऐसा करने का सबसे आसान तरीका नीचे दिए गए तरीके से होगा।
//where rc is an int variable if wondering :/
rc = sqlite3_prepare_v2(dbPointer, "pragma table_info ('your table name goes here')", -1, &stmt, NULL);
if (rc==SQLITE_OK)
{
//will continue to go down the rows (columns in your table) till there are no more
while(sqlite3_step(stmt) == SQLITE_ROW)
{
sprintf(colName, "%s", sqlite3_column_text(stmt, 1));
//do something with colName because it contains the column's name
}
}
'SQLite.swift' के विशेष मामले के लिए, [इस सवाल-जवाब को देखने के ] (कॉलम नामों की एक साधारण सूची के लिए http://stackoverflow.com/questions/36784596/how-to-get-a-list-of-column-names-with-sqlite-swift) कॉलम नामों की एक साधारण सूची के लिए या [यह एक] (http माइग्रेशन मुद्दों के लिए //stackoverflow.com/a/29866725/3681880)। – Suragch