#include #include #include #include #include #include #include "component.h" #include "tledit.h" #include "tledit.m" int main (int argc, char *argv[]) { glocal SSTRINGS comps; glocal const char *dbserv = "localhost"; glocal const char *db = "components"; glocal const char *user = nullptr; glocal const char *passwd = nullptr; glocal bool askpass = false; glocal bool all = false; glocal const char *section = nullptr; static const char *tb[]={"tlmpwork","tlmpsql",NULL}; int ret = (argc, argv, tb); fprintf (stderr,MSG_U(I_USAGESQL ,"component_sql [ options ] components\n" "\n" "Export components definition to an SQL database\n" "\n" "--all : Update all component found.\n" "--comp : Path of one comp file.\n" " This option may be repeated.\n" "--db : Database.\n" "--dbserv : Database server.\n" "--dbuser : Database user.\n" "--dbpass : Password to use.\n" "--askpass: Ask for the password.\n" "--section: Component section to update.\n" )); int ret = -1; if (strcmp(opt,"--comp")==0){ if (file_exist(val)){ glocal.comps.add (new SSTRING(val)); ret = 1; }else{ xconf_error (MSG_R(E_NOCOMPFILE),val); } }else if (strcmp(opt,"--dbserv")==0){ glocal.dbserv = val; ret = 1; }else if (strcmp(opt,"--db")==0){ glocal.db = val; ret = 1; }else if (strcmp(opt,"--dbuser")==0){ glocal.user = val; ret = 1; }else if (strcmp(opt,"--dbpass")==0){ glocal.passwd = val; ret = 1; }else if (strcmp(opt,"--askpass")==0){ glocal.askpass = true; ret = 0; }else if (strcmp(opt,"--all")==0){ glocal.all = true; ret = 0; }else if (strcmp(opt,"--section")==0){ glocal.section = val; ret = 1; } return ret; int ret = -1; if (!glocal.all && glocal.section == NULL){ usage(); }else{ ret = main(0,NULL); } return ret; SSTRING pass; if (glocal.askpass){ DIALOG dia; dia.newf_pass (MSG_U(F_DBPASS,"Database password"),pass); if (dia.edit("","",help_nil)==MENU_ACCEPT){ glocal.passwd = pass.get(); }else{ return -1; } dialog_end(); } if (glocal.comps.getnb()==0){ (); glocal.comps.add (new SSTRING (path)); } struct SECTINFO{ int id; SSTRING summary; }; glocal int argc = argc; glocal char **argv = argv; glocal SECTINFO sectinfo; query_setdefaultdb (glocal.dbserv,glocal.db,glocal.user,glocal.passwd); (glocal.comps,0); if (info.level == 1){ glocal.sectinfo.id=-1; ("select sectionid,summary from sections" " where section='%s'" ,name); glocal.sectinfo.id = atoi(row[0]); glocal.sectinfo.summary.setfrom (row[1]); if (glocal.sectinfo.id==-1){ printf ("Section %s not in database\n",name); NSQL_ENCODE enc; sql_action ("insert into sections (section,summary)" " values " " ('%s','%s')" ,enc.enc(name),enc.enc(summary)); // Fetch back the sectionid ("select sectionid from sections" " where section='%s'" ,name); glocal.sectinfo.id = atoi(row[0]); }else if (summary[0] != '\0' && glocal.sectinfo.summary.cmp(summary)!=0){ printf ("Update section %s summary\n",name); NSQL_ENCODE enc; sql_action ("update sections set summary='%s'" " where sectionid=%d" ,enc.enc(summary),glocal.sectinfo.id); } } skip = true; bool found = false; for (int i=0; i("select xml,summary,version,sectionid from components" " where component='%s' order by version desc limit 1",name); if (glocal.s.cmp(row[0])!=0 || strcmp(glocal.summary,row[1])!=0 || glocal.sectinfo.id != atoi(row[3])){ printf ("Updating component %s\n",glocal.name); glocal.version = atoi(row[2])+1; } printf ("Adding component %s\n",glocal.name); glocal.version = 0; if (glocal.version != -1){ NSQL_ENCODE enc; sql_action ("insert into components" " (component,isobj,summary,sectionid,packageid,version,xml)" " values" " ('%s','%c','%s',%d,%d,%d,'%s')" ,enc.enc(glocal.name) ,is_obj ? 'Y' : 'N' ,enc.enc(summary) ,glocal.sectinfo.id,0,glocal.version ,enc.enc(glocal.s.get())); } } return 0; return ret; }