Beispiel #1
0
EXPORT_C gint32 CContactDb::GetAllContactsByGroup(guint32 nGroupId, gboolean onlyPref, CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (onlyPref || !CheckGroupInTag(nGroupId, ContactType_Phone))
		sprintf(sql, "select * from contact c, r_contact_group r where r.gid = %d and ", nGroupId);
	else
		sprintf(sql, "select c.*, ext.* from contact c, r_contact_group r "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where r.gid = %d and ", nGroupId);
	
	strcat(sql, "c.cid = r.cid ");
	if (-1 != m_nSortFieldIndex)
		{
		strcat(sql, "order by c.");
		strcat(sql, ((GString*)g_ptr_array_index(m_pFieldsName, m_nSortFieldIndex))->str);
		strcat(sql, " asc;");
		}
		
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;
	}
//Sube el diccionario de campos a memoria..
int InicializaEstructuraCampos(int id)
{
        char szSql[1024];
	Tipo_XML *xml=NULL;
	int i,sts;
	char szAux[10];

	for(i=0;i<LEN_CAMPOS;i++)  stCampos[i].nValido=0;
			        
        sprintf(szSql,"select * from campos");
	if (!QueryDatabase(id,szSql)) goto fin;
	i=0;
	do
	{
	    xml=MoveNext(id,&sts);
	    if (sts!=DATOS_OK) break;
	   GetStrXML(xml,"NOMBRE",stCampos[i].szNombre,sizeof(stCampos[i].szNombre)); 
	   GetIntXML(xml,"LARGO",&stCampos[i].nLen);
	   GetStrXML(xml,"TIPO",stCampos[i].szTipo,sizeof(stCampos[i].szTipo));
	   
           stCampos[i].nValido=1;
	   i++;
	}while(1);
        CloseDatabase(id);
	CierraXML(xml);
	return 1;
fin:
        CloseDatabase(id);
     	CierraXML(xml);
       return 0;

}
Beispiel #3
0
EXPORT_C gint32 CContactDb::GetEntityById(guint32 nId, CDbEntity** ppEntity)
	{
	char sql[128] = {0};
	*ppEntity = NULL;
	
	OpenDatabase();
	sprintf(sql, "select * from contact where cid = %d;", nId);
	CppSQLite3Query query = m_dbBeluga.execQuery(sql);
	
	if (query.eof())
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_Not_Exist);
		}
	
	if (ContactType_Phone == query.getIntField(ContactField_Type))
		*ppEntity = new CPhoneContact(this, FALSE);
	else
		*ppEntity = new CIMContact(this);
	if (NULL == *ppEntity)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}
	
	for (int i=0; i<query.numFields(); i++)
		{
		GString * fieldValue = g_string_new(query.fieldValue(i));
		(*ppEntity)->SetFieldValue(i, fieldValue);
		g_string_free(fieldValue, TRUE);
		}
		
	CloseDatabase();
	return 0;
	}
int GetDatosCliente(int id,int nCliente,char szImagen[],char szPag[])
{
	char szSql[300];
	char szAux[100];
	Tipo_XML *xml=NULL;
	int sts;
	sprintf(szSql,"select tag_imagen,pagina_servicio from clientes where codigo=%i",nCliente);
	if (!QueryDatabase(id,szSql)) goto close;

	xml=MoveNext(id,&sts); 

	if (sts!=DATOS_OK) 
	{
		printf("El codigo %i, no existe en la tabla de clientes\n\r",nCliente);
		return 0;
	}
	CloseDatabase(id);
	GetStrXML(xml,"TAG_IMAGEN",szAux,sizeof(szAux));
	sprintf(szImagen,"%s",szAux);
	GetStrXML(xml,"PAGINA_SERVICIO",szAux,sizeof(szAux));
	sprintf(szPag,"%s",szAux);
	CierraXML(xml);
	return 1;
close:
	CloseDatabase(id);
	CierraXML(xml);
	return 0;
}
Beispiel #5
0
EXPORT_C gint32 CContactDb::SearchPhoneContactsByPhoneOrEmail(gchar * commValue, 
							gboolean onlyPref, CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (onlyPref)
		strcpy(sql, "select * from contact c where cid in (select cid from contact_ext where comm_value like '%");
	else
		strcpy(sql, "select c.*, ext.* from contact c "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where c.cid in (select cid from contact_ext where comm_value like '%");
	
	strcat(sql, commValue);
	strcat(sql, "%') order by c.name_spell asc;");				
		
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;
	}
Beispiel #6
0
EXPORT_C gint32 CContactDb::SearchContactsByName(guint32 nTagId, gchar* name, gboolean onlyPref, 
											CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (nTagId != ContactType_Phone)
		sprintf(sql, "select * from contact where nickname_spell like '%%%s%%'and type = %d order by nickname_spell asc;", name, nTagId);
	else if (onlyPref)
		sprintf(sql, "select * from contact where name_spell like '%%%s%%'and type = %d order by name_spell asc;", name, nTagId);
	else
		sprintf(sql, "select c.*, ext.* from contact c "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where name_spell like '%%%s%%'and type = %d order by name_spell asc;", name, nTagId);
							
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;	
	}
Beispiel #7
0
EXPORT_C gint32 CContactDb::GetRecentContacts(GPtrArray ** pContacts)
	{
	char sql[64] = {0};
	char times[20] = {0};
//	time_t t;
	
//	time(&t); 
	*pContacts = NULL;
	*pContacts = g_ptr_array_new();
	if (*pContacts == NULL)
		{
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}
	
	OpenDatabase();
	strcpy(sql, "select * from recent_contact;");
	CppSQLite3Query query = m_dbBeluga.execQuery(sql);
	while (!query.eof())
		{
		stRecentContact * recentContact = (stRecentContact*)g_malloc0(sizeof(stRecentContact));
		if (recentContact == NULL)
			{
			CloseDatabase();
			return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
			}
		
		recentContact->nContactId = query.getIntField(1);
		recentContact->event = (EContactEvent)query.getIntField(2);
		strcpy(recentContact->eventCommInfo, query.getStringField(3));
		strcpy(times, query.getStringField(4));  /* exp: 2009-6-30 21:51:23 */
 		//recentContact->time = localtime(&t); 
		GetLocalTime(&recentContact->time);
		char * tmp = strrchr(times, '-');
		recentContact->time.tm_mon = atoi(tmp+1);
		tmp = strrchr(tmp, '-');
		recentContact->time.tm_mday = atoi(tmp+1);
		tmp = strrchr(tmp, ' ');
		recentContact->time.tm_hour = atoi(tmp+1);
		tmp = strrchr(tmp, ':');
		recentContact->time.tm_min = atoi(tmp+1);
		tmp = strrchr(tmp, ':');
		recentContact->time.tm_sec = atoi(tmp+1);
		
		g_ptr_array_add(*pContacts, recentContact);
		query.nextRow();
		}
	
	CloseDatabase();
	return 0;
	}
Beispiel #8
0
/*  SRSendSymLocate - send a locate-symbol message to the server
 *
 *  Send request to server, display all responses until
 *  !EOM is seen.
 *
 *  psz 	symbol to find
 *  fFilesOnly	TRUE => just list filenames
 *  pszScope	scope of search
 */
void SRSendSymLocate (PSZ psz, BOOL fFilesOnly, PSZ pszScope)
{
    char sz[CBMSG];
    char *p;
    char szFile[MAX_PATH];
    HANDLE hServer;

    sprintf (sz, "%s %s %s %s", CMD_LOCATE, psz, fFilesOnly ? "-f" : "-a", pszScope);

    hServer = OpenDatabase (FALSE);

    SendSz (hServer, sz);

    while (ReceiveSz (hServer, sz)) {
	if (!strcmp (sz, RSP_EOD))
	    break;
	p = strbscan (sz, " ");
	*p++ = 0;

	GetLocalName (sz, szFile);

	if (fFilesOnly)
	    printf ("%s\n", szFile);
	else
	    printf ("%s %s\n", szFile, p);
	}

    CloseDatabase (hServer);
}
Beispiel #9
0
/*  SRSendAddDirectory - send an index-file request to server
 *
 *  psz     name of file to be indexed. This name is rootpath'd as the
 *          server may be operating on a different directory/drive
 */
void SRSendAddDirectory (PSZ psz)
{
    char szFile[MAX_PATH];

    {
	char szTmp[MAX_PATH];

	rootpath (psz, szTmp);

	GetGlobalName (szTmp, szFile);
    }

    {
	HANDLE hServer;
	char sz[CBMSG];

	sprintf (sz, "%s %s", CMD_ADD_DIRECTORY, szFile);

	printf ("%s", szFile);

	hServer = OpenDatabase (TRUE);

	SendSz (hServer, sz);

	CloseDatabase (hServer);

	printf ("\n");
    }

}
Beispiel #10
0
/*  SRSendNewDatabase - send a change-database request to server
 *
 *  psz     name of new database.  This name is rootpath'd as the
 *          server may be operating on a different directory/drive
 */
void SRSendNewDatabase (PSZ psz)
{
    char szFile[MAX_PATH];

    {
	char szTmp[MAX_PATH];

	rootpath (psz, szTmp);

	GetGlobalName (szTmp, szFile);
    }

    {
	HANDLE hServer;
	char sz[CBMSG];

	sprintf (sz, "%s %s", CMD_SET_DATABASE, szFile);

	hServer = OpenDatabase (FALSE);

	SendSz (hServer, sz);

	CloseDatabase (hServer);
    }
}
Beispiel #11
0
void CConcurrentDatabaseAccessBase::RunTestL()
	{
	// set's up an active scheduler for the thread
	// and calls the RunTesImplementation function to actually
	// preform the tests. This function should be implemented in the
	// child class.
	CTestActiveScheduler*  scheduler = NULL;

	scheduler = new (ELeave) CTestActiveScheduler;
	CleanupStack::PushL(scheduler);
	CActiveScheduler::Install(scheduler);

	CActiveScheduler::Add( this );

	OpenDatabaseL();

	CallRunLAgain();
	CActiveScheduler::Start();

	CloseDatabase();

	CleanupStack::PopAndDestroy( scheduler );

	// propagate error
	User::LeaveIfError(iTestError);
	}
Beispiel #12
0
bool TStatDatabase::LoadDatabase(const char* lpFileName)
{
    CloseDatabase();
	TiXmlDocument doc(lpFileName);
    if (!doc.LoadFile())
		return false;
    TiXmlHandle hDoc(&doc);
    TiXmlHandle hRoot(0);
	TiXmlElement* elem = hDoc.FirstChildElement().Element();
    if (strcmp(elem->Value(), "awpStatDB") != 0)
        return false;

    for(TiXmlNode* child = elem->FirstChild(); child; child = child->NextSibling() )
    {
        const char* name = child->Value();
        if (strcmp(name, "EntryID") != 0)
            return false;
        TDbEntry* e = new TDbEntry(0, "");
        if (e->LoadXML(child->ToElement()))
            this->m_entries.Add(e);
        else
        {
            delete e;
            return false;
        }

    }
    this->m_isChanged = false;
    this->m_dbName = lpFileName;
    return true;
}
Beispiel #13
0
EXPORT_C gint32 CContactDb::SaveRecentContact(stRecentContact * contact)
	{
	char sql[256] = {0};
	OpenDatabase();
	if (m_dbBeluga.execScalar("select count(*) from recent_contact;") > MAX_RECENT_CONTACT_NUM)
		{
		m_dbBeluga.execDML("delete from recent_contact where time = (select min(time) from recent_contact);");
		}
	
	sprintf(sql, "select count(*) from recent_contact where cid = %d;", contact->nContactId);
	if (m_dbBeluga.execScalar(sql) != 0)
		{
		memset(sql, 0, 256);
		sprintf(sql, "update recent_contact set event = %d, event_comm = '%s', time = '%d-%d-%d %02d:%02d:%02d' where cid = %d;", 
			contact->event, contact->eventCommInfo,
			contact->time.tm_year, contact->time.tm_mon, contact->time.tm_mday,
			contact->time.tm_hour, contact->time.tm_min, contact->time.tm_sec, contact->nContactId);
		}
		else
		{
		memset(sql, 0, 256);
		sprintf(sql, "insert into recent_contact values(null, %d, %d, '%s', %d-%d-%d %02d:%02d:%02d);", 
			contact->nContactId, contact->event, contact->eventCommInfo,
			contact->time.tm_year, contact->time.tm_mon, contact->time.tm_mday,
			contact->time.tm_hour, contact->time.tm_min, contact->time.tm_sec);
		}

	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
Beispiel #14
0
   bool
   Application::ExitInstance()
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Do uninitialization.
   //---------------------------------------------------------------------------()
   {
      // Close work queue
      WorkQueueManager::Instance()->RemoveQueue(m_sMaintenanceQueue);

      WorkQueueManager::Instance()->RemoveQueue(m_sAsynchronousTasksQueue);

      // Backup manager is created by initinstance so should be destroyed here.
      if (m_pBackupManager) 
         m_pBackupManager.reset();

      LOG_DEBUG("Application::ExitInstance - Closing database connection...");
      CloseDatabase();

      LOG_DEBUG("Application::ExitInstance - Deleting caches...");
      CacheContainer::Instance()->DeleteCaches();

      MimeEnvironment::SetAutoFolding(false);

      OutOfMemoryHandler::Terminate();
 
      return 0;
    
   }
Beispiel #15
0
EXPORT_C gint32 CContactDb::GetMaxId(guint32 * nMaxId)
	{
	OpenDatabase();
	*nMaxId = m_dbBeluga.execScalar("select max(cid) from contact;");
	CloseDatabase();
	return 0;
	}
int DatosProceso(int id,Tipo_Proceso *pProceso,char szProceso[])
{
	char szSql[1000];
	Tipo_XML *xml=NULL;
	int sts;
	sprintf(szSql,"select ip,cantidad,port from procesos where proceso='%s'",szProceso);
	xml=GetRecord(id,szSql,xml,&sts);
	if (sts==0) 
	{
		printf("El proceso %s, no existe en la tabla de procesos\n\r",szProceso);
		xml=CierraXML(xml);
		exit(1);
	}

	//ImprimeXML(xml);
	if (!GetIntXML(xml,"CANTIDAD",&pProceso->nCantidad)) goto close;
	if (!GetIntXML(xml,"PORT",&pProceso->nPort)) goto close;
	//if (!GetIntXML(xml,"FORMA_CONEXION_BD",&pProceso->nFormaConexionBD)) goto close;
	GetStrXML(xml,"IP",pProceso->szIp,sizeof(pProceso->szIp));
	xml=CierraXML(xml);
	global.nProcesos = pProceso->nCantidad;
	return 1;
close:
	CloseDatabase(id);
	exit(1);
}
Beispiel #17
0
gboolean CContactDb::IsInRecentContact(guint32 nContactId)
	{
	char sql[256] = {0};
	OpenDatabase();
	sprintf(sql, "select count(*) from recent_contact where cid = %d;", nContactId);
	if (m_dbBeluga.execScalar(sql) == 0)
		{
		CloseDatabase();
		return FALSE;
		}
	else
		{
		CloseDatabase();
		return TRUE;
		}
	}
Beispiel #18
0
///////////////////////////////////////////////////////////////////////////
//	Name:	SaveDatabaseNow
//
//	Description:
//	Remember the name and path of the currently open database.  Close the database
//	to flush all buffers, then reopen it.
//	
//	Declaration:
//	bool CDbVista::SaveDatabaseNow();
//
//	Input:	none
//
//	Output:	none
//
//	Return:	true (db saved) / false (error when reopening)
//	
//  date    /	author	revision
//  -----------------	--------
//	03-Dec-2001	SFK		Created from SaveDatabaseNow in DbGeneralDbSupport.cpp
//////////////////////////////////////////////////////////////////
bool CDbVista::SaveDatabaseNow()
{

//	SetCurrentDrive();		// implement in new version?? SFK
	CloseDatabase();
	return (OpenDatabase(mstrDatabasePath, mstrDatabaseName));
}
Beispiel #19
0
EXPORT_C gint32 CContactDb::SearchContactsByTag(guint32 nTagId, GArray * fieldsIndex, GPtrArray * fieldsValue, 
							gboolean onlyPref, CContactIterator ** ppContactIterator)
	{
	char sql[512] = {0};
	OpenDatabase();
	
	if (onlyPref || nTagId != ContactType_Phone)
		strcpy(sql, "select * from contact c where ");
	else
		strcpy(sql, "select c.*, ext.* from contact c "\
					"left join (select ce.cid ,ce.comm_key, ce.comm_value, a.* from contact_ext ce "\
					"left join address a on ce.comm_value = a.aid) ext "\
					"on c.cid = ext.cid where ");
		
	for (guint32 i=0; i<fieldsIndex->len; i++)
		for (guint32 j=ContactField_UserId; j<ContactField_EndFlag; j++)
			{
			if (g_array_index(fieldsIndex, guint32, i) == j)
				{
				strcat(sql, ((GString*)g_ptr_array_index(m_pFieldsName, j))->str);
				strcat(sql, " like '%");
				strcat(sql, ((GString*)g_ptr_array_index(fieldsValue, i))->str);
				strcat(sql, "%' and");				
				}
			}
	
	strcat(sql, "c.cid >= 0 ");
	
	if (-1 != m_nSortFieldIndex)
		{
		strcat(sql, "order by c.");
		strcat(sql, ((GString*)g_ptr_array_index(m_pFieldsName, m_nSortFieldIndex))->str);
		strcat(sql, " asc;");
		}
		
	m_dbQuery = m_dbBeluga.execQuery(sql);
	*ppContactIterator = NULL;
	*ppContactIterator = new CContactIterator(this, onlyPref);
	if (NULL == *ppContactIterator)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}

	CloseDatabase();
	return 0;
	}
Beispiel #20
0
CContactDatabase* CCntClient::CreateDatabaseL()
	{
	CloseDatabase();
	iDb=CContactDatabase::ReplaceL(iDatabaseName);
	iNotifier = CContactChangeNotifier::NewL(*iDb,this);
	iObservers++; //
	return(iDb);
	}
Beispiel #21
0
gint32 CContactDb::GetMaxContactCommId(guint32 * pMaxCommId)
	{
	*pMaxCommId = 0;
	OpenDatabase();
	*pMaxCommId = m_dbBeluga.execScalar("select max(ce_id) from contact_ext;");
	CloseDatabase();
	return 0;
	}
Beispiel #22
0
EXPORT_C gint32 CContactDb::CreateContactGroupRelation(guint32 nContactId, guint32 nGroupId)
	{
	char sql[128] = {0};
	OpenDatabase();
	sprintf(sql, "insert into r_contact_group values(%d, %d);", nContactId, nGroupId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
Beispiel #23
0
EXPORT_C gint32 CContactDb::DeleteEntity(guint32 nEntityId)
	{
	char sql[128] = {0};
	OpenDatabase();
	sprintf(sql, "delete from contact where cid = %d;", nEntityId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
Beispiel #24
0
EXPORT_C gint32 CContactDb::InitEntityDb(gchar* dbName) /* fill fields name */
	{
	strcpy(m_dbName, dbName);
	OpenDatabase();
	CppSQLite3Table contactTable = m_dbBeluga.getTable("select * from contact limit 1;");
	m_pFieldsName = g_ptr_array_sized_new(contactTable.numFields());
	if (!m_pFieldsName)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}
			
	for (int i=0; i<contactTable.numFields(); i++)
		g_ptr_array_add(m_pFieldsName, g_string_new((gchar*)contactTable.fieldName(i)));
	
	CloseDatabase();
	return 0;
	}
Beispiel #25
0
EXPORT_C gint32 CContactDb::ReleaseContactAllRelations(guint32 nContactId)
	{
	char sql[128] = {0};
	OpenDatabase();
	sprintf(sql, "delete from r_contact_group where cid = %d;", nContactId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
Beispiel #26
0
/***********************************************************************
 * application is finished, so we have to clean the desktop behind us
 ***********************************************************************/
static void
StopApplication (void)
{
  gPrefs.curCat = DatabaseGetCat();
  PrefSavePrefs(&gPrefs);
  FrmCloseAllForms ();
  CacheFree();
  CloseDatabase();
}
Beispiel #27
0
/*  SRSendSync - send a sync request to server
 */
void SRSendSync ()
{
    HANDLE hServer;

    hServer = OpenDatabase (FALSE);

    SendSz (hServer, CMD_SYNCHRONIZE);

    CloseDatabase (hServer);
}
Beispiel #28
0
EXPORT_C gint32 CContactDb::DeleteAllContactsByTag(guint32 nTagId)
	{
	char sql[256] = {0};
	OpenDatabase();
	sprintf(sql, "delete from contact where cid in (select cid from r_contact_group where gid in "\
				 "(select gid from cgroup where tid= %d)); ", nTagId);
	m_dbBeluga.execDML(sql);
	CloseDatabase();
	return 0;
	}
Beispiel #29
0
EXPORT_C gint32 CContactDb::GetContactsTotalityByGroup(guint32 nGroupId, guint32 * totality)
	{
	char sql[128] = {0};
	*totality = 0;
	OpenDatabase();
	
	sprintf(sql, "select count(cid) from r_contact_group where gid = %d;", nGroupId);
	*totality = m_dbBeluga.execScalar(sql);
	CloseDatabase();
	
	return 0;
	}
Beispiel #30
0
EXPORT_C gint32 CContactDb::GetContactsTotalityByTag(guint32 nTagId, guint32 * totality)
	{
	char sql[128] = {0};
	*totality = 0;
	OpenDatabase();
	
	sprintf(sql, "select count(*) from contact where type = %d;", nTagId);
	*totality = m_dbBeluga.execScalar(sql);
	CloseDatabase();
	
	return 0;
	}