Loading src/sqlite3gen.cpp +25 −17 Original line number Original line Diff line number Diff line Loading @@ -77,9 +77,9 @@ const char *i_q_xrefs="INSERT OR REPLACE INTO xrefs " static sqlite3_stmt *i_s_xrefs=0; static sqlite3_stmt *i_s_xrefs=0; ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// const char *i_q_memberdef="INSERT OR REPLACE INTO memberdef " const char *i_q_memberdef="INSERT OR REPLACE INTO memberdef " "( refid, prot, static, const, explicit, inline, final, sealed, new, optional, required, virt, mutable, initonly, readable, writable, gettable, settable, accessor, addable, removable, raisable, name, type, definition, argsstring, scope, initializer, kind, id_bfile, bline, bcolumn, id_file, line, column)" "( refid, prot, static, const, explicit, inline, final, sealed, new, optional, required, virt, mutable, initonly, readable, writable, gettable, settable, accessor, addable, removable, raisable, name, type, definition, argsstring, scope, initializer, kind, id_bodyfile, bodystart, bodyend, id_file, line, column, detaileddescription, briefdescription, inbodydescription)" "VALUES " "VALUES " "(:refid,:prot,:static,:const,:explicit,:inline,:final,:sealed,:new,:optional,:required,:virt,:mutable,:initonly,:readable,:writable,:gettable,:settable,:accessor,:addable,:removable,:raisable,:name,:type,:definition,:argsstring,:scope,:initializer,:kind,:id_bfile,:bline,:bcolumn,:id_file,:line,:column)"; "(:refid,:prot,:static,:const,:explicit,:inline,:final,:sealed,:new,:optional,:required,:virt,:mutable,:initonly,:readable,:writable,:gettable,:settable,:accessor,:addable,:removable,:raisable,:name,:type,:definition,:argsstring,:scope,:initializer,:kind,:id_bodyfile,:bodystart,:bodyend,:id_file,:line,:column,:detaileddescription,:briefdescription,:inbodydescription)"; const char *id_q_memberdef="SELECT id FROM memberdef WHERE refid=:refid and id is not null"; const char *id_q_memberdef="SELECT id FROM memberdef WHERE refid=:refid and id is not null"; static sqlite3_stmt *id_s_memberdef=0; static sqlite3_stmt *id_s_memberdef=0; static sqlite3_stmt *i_s_memberdef=0; static sqlite3_stmt *i_s_memberdef=0; Loading Loading @@ -202,12 +202,16 @@ const char * schema_queries[][2] = "raisable INTEGER," "raisable INTEGER," "kind INTEGER," "kind INTEGER," "refid TEXT NOT NULL," "refid TEXT NOT NULL," "id_bfile INTEGER," "id_bodyfile INTEGER," "bline INTEGER," "bodystart INTEGER," "bcolumn INTEGER," "bodyend INTEGER," "id_file INTEGER NOT NULL," "id_file INTEGER NOT NULL," "line INTEGER NOT NULL," "line INTEGER NOT NULL," "column INTEGER NOT NULL)" "column INTEGER NOT NULL," "detaileddescription TEXT," "briefdescription TEXT," "inbodydescription TEXT" ")" }, }, }; }; Loading Loading @@ -692,6 +696,12 @@ static void generateSqlite3ForMember(sqlite3*db,MemberDef *md,Definition *def) bindTextParameter(i_s_memberdef,":scope",md->getScopeString().data(),FALSE); bindTextParameter(i_s_memberdef,":scope",md->getScopeString().data(),FALSE); } } // Brief and detail description bindTextParameter(i_s_memberdef,":briefdescription",md->briefDescription(),FALSE); bindTextParameter(i_s_memberdef,":detaileddescription",md->documentation(),FALSE); bindTextParameter(i_s_memberdef,":inbodydescription",md->inbodyDocumentation(),FALSE); // File location // File location if (md->getDefLine() != -1) if (md->getDefLine() != -1) { { Loading @@ -704,18 +714,16 @@ static void generateSqlite3ForMember(sqlite3*db,MemberDef *md,Definition *def) if (md->getStartBodyLine()!=-1) if (md->getStartBodyLine()!=-1) { { int id_bfile = insertFile(db,md->getBodyDef()->absFilePath()); int id_bodyfile = insertFile(db,md->getBodyDef()->absFilePath()); if (id_bfile == -1) if (id_bodyfile == -1) { { sqlite3_clear_bindings(i_s_memberdef); sqlite3_clear_bindings(i_s_memberdef); } } else else { { bindIntParameter(i_s_memberdef,":id_ibfile",id_bfile); bindIntParameter(i_s_memberdef,":id_bodyfile",id_bodyfile); bindIntParameter(i_s_memberdef,":bline",md->getStartBodyLine()); bindIntParameter(i_s_memberdef,":bodystart",md->getStartBodyLine()); bindIntParameter(i_s_memberdef,":bodyend",md->getEndBodyLine()); // XXX implement getStartBodyColumn bindIntParameter(i_s_memberdef,":bcolumn",1); } } } } } } Loading Loading @@ -837,19 +845,19 @@ static void generateSqlite3ForClass(sqlite3 *db, ClassDef *cd) BaseClassDef *bcd; BaseClassDef *bcd; for (bcli.toFirst();(bcd=bcli.current());++bcli) for (bcli.toFirst();(bcd=bcli.current());++bcli) { { bindTextParameter(i_s_basecompoundref,":refid",bcd->classDef->getOutputFileBase()); bindTextParameter(i_s_basecompoundref,":refid",bcd->classDef->getOutputFileBase(),FALSE); bindIntParameter(i_s_basecompoundref,":prot",bcd->prot); bindIntParameter(i_s_basecompoundref,":prot",bcd->prot); bindIntParameter(i_s_basecompoundref,":virt",bcd->virt); bindIntParameter(i_s_basecompoundref,":virt",bcd->virt); if (!bcd->templSpecifiers.isEmpty()) if (!bcd->templSpecifiers.isEmpty()) { { bindTextParameter(i_s_basecompoundref,":base",insertTemplateSpecifierInScope(bcd->classDef->name(),bcd->templSpecifiers)); bindTextParameter(i_s_basecompoundref,":base",insertTemplateSpecifierInScope(bcd->classDef->name(),bcd->templSpecifiers),FALSE); } } else else { { bindTextParameter(i_s_basecompoundref,":base",bcd->classDef->displayName()); bindTextParameter(i_s_basecompoundref,":base",bcd->classDef->displayName(),FALSE); } } bindTextParameter(i_s_basecompoundref,":derived",cd->displayName()); bindTextParameter(i_s_basecompoundref,":derived",cd->displayName(),FALSE); if (-1==step(db,i_s_basecompoundref)) { if (-1==step(db,i_s_basecompoundref)) { sqlite3_clear_bindings(i_s_basecompoundref); sqlite3_clear_bindings(i_s_basecompoundref); continue; continue; Loading testing/testsqlite3.py 0 → 100755 +146 −0 Original line number Original line Diff line number Diff line #! /usr/bin/python from xml.etree import cElementTree as ET import os import sqlite3 import sys import getopt # map XML attributes/elements to SQL rows # --POC: iterate through the children and attributes of the memberdef elelement # and search it in doxygen_sqlite3.db g_conn=None val=[] def print_unprocessed_attributes(node): for key in node.attrib: print "WARNING: '%s' has unprocessed attr '%s'" % (node.tag,key) def extract_attribute(node,attribute,pnl): if not attribute in node.attrib: return pnl.append("%s = ?" % attribute) val.append(node.attrib[attribute]) node.attrib.pop(attribute) def extract_element(node,chld,pnl): # deal with <tag /> if chld.text == None: if len(chld.attrib)==0: node.remove(chld) return a=chld.text.strip() if not a == "": pnl.append("%s =?" % chld.tag) val.append(chld.text.strip()) else: pnl.append("%s IS NULL OR %s = ''" % (chld.tag,chld.tag)) node.remove(chld) def process_memberdef(node): q=[] for chld in node.getchildren(): if chld.tag == "referencedby": continue if chld.tag == "references": continue if chld.tag == "param": continue if chld.tag == "type": continue if chld.tag == "location": extract_attribute(chld,"line",q) extract_attribute(chld,"column",q) extract_attribute(chld,"bodystart",q) extract_attribute(chld,"bodyend",q) q.append("id_bodyfile=(select id from files where name=?)") val.append(chld.attrib["bodyfile"]) chld.attrib.pop("bodyfile") q.append("id_file=(select id from files where name=?)") val.append(chld.attrib["file"]) chld.attrib.pop("file") print_unprocessed_attributes(chld) if len(chld.attrib) == 0: node.remove(chld) else: extract_element(node,chld,q) for chld in node.getchildren(): print "WARNING: '%s' has unprocessed child elem '%s'" % (node.tag,chld.tag) extract_attribute(node,"kind",q) extract_attribute(node,"prot",q) extract_attribute(node,"static",q) extract_attribute(node,"mutable",q) extract_attribute(node,"const",q) extract_attribute(node,"virt",q) extract_attribute(node,"explicit",q) extract_attribute(node,"inline",q) q.append("refid=?") val.append(node.attrib['id']) node.attrib.pop('id') print_unprocessed_attributes(node) query="SELECT * FROM memberdef WHERE %s" % " AND ".join(q) r=[] try: r = g_conn.execute(query,val).fetchall() except sqlite3.OperationalError,e: print "SQL_ERROR:%s"%e del val[:] if not len(r) > 0: print "TEST_ERROR: Member not found in SQL DB" def load_xml(name): context = ET.iterparse(name, events=("start", "end")) event, root = context.next() for event, elem in context: if event == "end" and elem.tag == "memberdef": process_memberdef(elem) print "\n== Unprocessed XML ==" # ET.dump(root) def open_db(dbname): global g_conn if dbname == None: dbname = "doxygen_sqlite3.db" if not os.path.isfile(dbname): raise BaseException("No such file %s" % dbname ) g_conn = sqlite3.connect(dbname) g_conn.execute('PRAGMA temp_store = MEMORY;') g_conn.row_factory = sqlite3.Row def main(argv): try: opts, args = getopt.getopt(argv, "hd:x:",["help"]) except getopt.GetoptError: sys.exit(1) dbname=None xmlfile=None for a, o in opts: if a in ('-h', '--help'): sys.exit(0) elif a in ('-d'): dbname=o continue elif a in ('-x'): xmlfile=o continue open_db(dbname) load_xml(xmlfile) if __name__ == '__main__': main(sys.argv[1:]) Loading
src/sqlite3gen.cpp +25 −17 Original line number Original line Diff line number Diff line Loading @@ -77,9 +77,9 @@ const char *i_q_xrefs="INSERT OR REPLACE INTO xrefs " static sqlite3_stmt *i_s_xrefs=0; static sqlite3_stmt *i_s_xrefs=0; ////////////////////////////////////////////////////// ////////////////////////////////////////////////////// const char *i_q_memberdef="INSERT OR REPLACE INTO memberdef " const char *i_q_memberdef="INSERT OR REPLACE INTO memberdef " "( refid, prot, static, const, explicit, inline, final, sealed, new, optional, required, virt, mutable, initonly, readable, writable, gettable, settable, accessor, addable, removable, raisable, name, type, definition, argsstring, scope, initializer, kind, id_bfile, bline, bcolumn, id_file, line, column)" "( refid, prot, static, const, explicit, inline, final, sealed, new, optional, required, virt, mutable, initonly, readable, writable, gettable, settable, accessor, addable, removable, raisable, name, type, definition, argsstring, scope, initializer, kind, id_bodyfile, bodystart, bodyend, id_file, line, column, detaileddescription, briefdescription, inbodydescription)" "VALUES " "VALUES " "(:refid,:prot,:static,:const,:explicit,:inline,:final,:sealed,:new,:optional,:required,:virt,:mutable,:initonly,:readable,:writable,:gettable,:settable,:accessor,:addable,:removable,:raisable,:name,:type,:definition,:argsstring,:scope,:initializer,:kind,:id_bfile,:bline,:bcolumn,:id_file,:line,:column)"; "(:refid,:prot,:static,:const,:explicit,:inline,:final,:sealed,:new,:optional,:required,:virt,:mutable,:initonly,:readable,:writable,:gettable,:settable,:accessor,:addable,:removable,:raisable,:name,:type,:definition,:argsstring,:scope,:initializer,:kind,:id_bodyfile,:bodystart,:bodyend,:id_file,:line,:column,:detaileddescription,:briefdescription,:inbodydescription)"; const char *id_q_memberdef="SELECT id FROM memberdef WHERE refid=:refid and id is not null"; const char *id_q_memberdef="SELECT id FROM memberdef WHERE refid=:refid and id is not null"; static sqlite3_stmt *id_s_memberdef=0; static sqlite3_stmt *id_s_memberdef=0; static sqlite3_stmt *i_s_memberdef=0; static sqlite3_stmt *i_s_memberdef=0; Loading Loading @@ -202,12 +202,16 @@ const char * schema_queries[][2] = "raisable INTEGER," "raisable INTEGER," "kind INTEGER," "kind INTEGER," "refid TEXT NOT NULL," "refid TEXT NOT NULL," "id_bfile INTEGER," "id_bodyfile INTEGER," "bline INTEGER," "bodystart INTEGER," "bcolumn INTEGER," "bodyend INTEGER," "id_file INTEGER NOT NULL," "id_file INTEGER NOT NULL," "line INTEGER NOT NULL," "line INTEGER NOT NULL," "column INTEGER NOT NULL)" "column INTEGER NOT NULL," "detaileddescription TEXT," "briefdescription TEXT," "inbodydescription TEXT" ")" }, }, }; }; Loading Loading @@ -692,6 +696,12 @@ static void generateSqlite3ForMember(sqlite3*db,MemberDef *md,Definition *def) bindTextParameter(i_s_memberdef,":scope",md->getScopeString().data(),FALSE); bindTextParameter(i_s_memberdef,":scope",md->getScopeString().data(),FALSE); } } // Brief and detail description bindTextParameter(i_s_memberdef,":briefdescription",md->briefDescription(),FALSE); bindTextParameter(i_s_memberdef,":detaileddescription",md->documentation(),FALSE); bindTextParameter(i_s_memberdef,":inbodydescription",md->inbodyDocumentation(),FALSE); // File location // File location if (md->getDefLine() != -1) if (md->getDefLine() != -1) { { Loading @@ -704,18 +714,16 @@ static void generateSqlite3ForMember(sqlite3*db,MemberDef *md,Definition *def) if (md->getStartBodyLine()!=-1) if (md->getStartBodyLine()!=-1) { { int id_bfile = insertFile(db,md->getBodyDef()->absFilePath()); int id_bodyfile = insertFile(db,md->getBodyDef()->absFilePath()); if (id_bfile == -1) if (id_bodyfile == -1) { { sqlite3_clear_bindings(i_s_memberdef); sqlite3_clear_bindings(i_s_memberdef); } } else else { { bindIntParameter(i_s_memberdef,":id_ibfile",id_bfile); bindIntParameter(i_s_memberdef,":id_bodyfile",id_bodyfile); bindIntParameter(i_s_memberdef,":bline",md->getStartBodyLine()); bindIntParameter(i_s_memberdef,":bodystart",md->getStartBodyLine()); bindIntParameter(i_s_memberdef,":bodyend",md->getEndBodyLine()); // XXX implement getStartBodyColumn bindIntParameter(i_s_memberdef,":bcolumn",1); } } } } } } Loading Loading @@ -837,19 +845,19 @@ static void generateSqlite3ForClass(sqlite3 *db, ClassDef *cd) BaseClassDef *bcd; BaseClassDef *bcd; for (bcli.toFirst();(bcd=bcli.current());++bcli) for (bcli.toFirst();(bcd=bcli.current());++bcli) { { bindTextParameter(i_s_basecompoundref,":refid",bcd->classDef->getOutputFileBase()); bindTextParameter(i_s_basecompoundref,":refid",bcd->classDef->getOutputFileBase(),FALSE); bindIntParameter(i_s_basecompoundref,":prot",bcd->prot); bindIntParameter(i_s_basecompoundref,":prot",bcd->prot); bindIntParameter(i_s_basecompoundref,":virt",bcd->virt); bindIntParameter(i_s_basecompoundref,":virt",bcd->virt); if (!bcd->templSpecifiers.isEmpty()) if (!bcd->templSpecifiers.isEmpty()) { { bindTextParameter(i_s_basecompoundref,":base",insertTemplateSpecifierInScope(bcd->classDef->name(),bcd->templSpecifiers)); bindTextParameter(i_s_basecompoundref,":base",insertTemplateSpecifierInScope(bcd->classDef->name(),bcd->templSpecifiers),FALSE); } } else else { { bindTextParameter(i_s_basecompoundref,":base",bcd->classDef->displayName()); bindTextParameter(i_s_basecompoundref,":base",bcd->classDef->displayName(),FALSE); } } bindTextParameter(i_s_basecompoundref,":derived",cd->displayName()); bindTextParameter(i_s_basecompoundref,":derived",cd->displayName(),FALSE); if (-1==step(db,i_s_basecompoundref)) { if (-1==step(db,i_s_basecompoundref)) { sqlite3_clear_bindings(i_s_basecompoundref); sqlite3_clear_bindings(i_s_basecompoundref); continue; continue; Loading
testing/testsqlite3.py 0 → 100755 +146 −0 Original line number Original line Diff line number Diff line #! /usr/bin/python from xml.etree import cElementTree as ET import os import sqlite3 import sys import getopt # map XML attributes/elements to SQL rows # --POC: iterate through the children and attributes of the memberdef elelement # and search it in doxygen_sqlite3.db g_conn=None val=[] def print_unprocessed_attributes(node): for key in node.attrib: print "WARNING: '%s' has unprocessed attr '%s'" % (node.tag,key) def extract_attribute(node,attribute,pnl): if not attribute in node.attrib: return pnl.append("%s = ?" % attribute) val.append(node.attrib[attribute]) node.attrib.pop(attribute) def extract_element(node,chld,pnl): # deal with <tag /> if chld.text == None: if len(chld.attrib)==0: node.remove(chld) return a=chld.text.strip() if not a == "": pnl.append("%s =?" % chld.tag) val.append(chld.text.strip()) else: pnl.append("%s IS NULL OR %s = ''" % (chld.tag,chld.tag)) node.remove(chld) def process_memberdef(node): q=[] for chld in node.getchildren(): if chld.tag == "referencedby": continue if chld.tag == "references": continue if chld.tag == "param": continue if chld.tag == "type": continue if chld.tag == "location": extract_attribute(chld,"line",q) extract_attribute(chld,"column",q) extract_attribute(chld,"bodystart",q) extract_attribute(chld,"bodyend",q) q.append("id_bodyfile=(select id from files where name=?)") val.append(chld.attrib["bodyfile"]) chld.attrib.pop("bodyfile") q.append("id_file=(select id from files where name=?)") val.append(chld.attrib["file"]) chld.attrib.pop("file") print_unprocessed_attributes(chld) if len(chld.attrib) == 0: node.remove(chld) else: extract_element(node,chld,q) for chld in node.getchildren(): print "WARNING: '%s' has unprocessed child elem '%s'" % (node.tag,chld.tag) extract_attribute(node,"kind",q) extract_attribute(node,"prot",q) extract_attribute(node,"static",q) extract_attribute(node,"mutable",q) extract_attribute(node,"const",q) extract_attribute(node,"virt",q) extract_attribute(node,"explicit",q) extract_attribute(node,"inline",q) q.append("refid=?") val.append(node.attrib['id']) node.attrib.pop('id') print_unprocessed_attributes(node) query="SELECT * FROM memberdef WHERE %s" % " AND ".join(q) r=[] try: r = g_conn.execute(query,val).fetchall() except sqlite3.OperationalError,e: print "SQL_ERROR:%s"%e del val[:] if not len(r) > 0: print "TEST_ERROR: Member not found in SQL DB" def load_xml(name): context = ET.iterparse(name, events=("start", "end")) event, root = context.next() for event, elem in context: if event == "end" and elem.tag == "memberdef": process_memberdef(elem) print "\n== Unprocessed XML ==" # ET.dump(root) def open_db(dbname): global g_conn if dbname == None: dbname = "doxygen_sqlite3.db" if not os.path.isfile(dbname): raise BaseException("No such file %s" % dbname ) g_conn = sqlite3.connect(dbname) g_conn.execute('PRAGMA temp_store = MEMORY;') g_conn.row_factory = sqlite3.Row def main(argv): try: opts, args = getopt.getopt(argv, "hd:x:",["help"]) except getopt.GetoptError: sys.exit(1) dbname=None xmlfile=None for a, o in opts: if a in ('-h', '--help'): sys.exit(0) elif a in ('-d'): dbname=o continue elif a in ('-x'): xmlfile=o continue open_db(dbname) load_xml(xmlfile) if __name__ == '__main__': main(sys.argv[1:])