Exemple #1
0
bool ibanBic::writeQuery(QSqlQuery& query, const QString& id) const
{
  query.bindValue(":id", id);
  query.bindValue(":iban", electronicIban());
  const QString bic = fullStoredBic();
  query.bindValue(":bic", (bic.isEmpty()) ? QVariant(QVariant::String) : bic);
  query.bindValue(":name", ownerName());
  if (!query.exec()) {
    qWarning("Error while saving ibanbic data for '%s': %s", qPrintable(id), qPrintable(query.lastError().text()));
    return false;
  }
  return true;
}
FdoSmPhReaderP FdoSmPhRdPostGisColumnReader::MakeQueryReader(
    FdoSmPhOwnerP owner,
    FdoStringsP objectNames,
    FdoSmPhRdTableJoinP join)
{
    mSize = 0;
    mScale = 0;

    FdoStringP sql;

    FdoStringP ownerName(owner->GetName());

    FdoSmPhMgrP          mgr = owner->GetManager();
    FdoSmPhPostGisMgrP   pgMgr = mgr->SmartCast<FdoSmPhPostGisMgr>();

    FdoSmPhPostGisOwnerP pgOwner = owner->SmartCast<FdoSmPhPostGisOwner>();
    assert(NULL != pgOwner);

    FdoStringP columnsTableName(pgOwner->GetColumnsTable());

    // template_postgis=# \d information_schema.columns
    //          Column          |     Type        | 
    // -------------------------+-----------------+
    // table_catalog            | sql_identifier  | <- Always the current database
    // table_schema             | sql_identifier  | <- Schema in the current database
    // table_name               | sql_identifier  |
    // column_name              | sql_identifier  |
    // ordinal_position         | cardinal_number | <- Count starts at 1
    // column_default           | character_data  |
    // is_nullable              | character_data  |
    // data_type                | character_data  |
    // character_maximum_length | cardinal_number | <- NULL for non-text/non-bit-string types 
    // character_octet_length   | cardinal_number | <- NULL for non-text types 
    // numeric_precision        | cardinal_number |
    // numeric_precision_radix  | cardinal_number |
    // numeric_scale            | cardinal_number |
    // character_set_name       | sql_identifier  | <- Not avilable in PostgreSQL
    // collation_name           | sql_identifier  | <- Not avilable in PostgreSQL
    // is_updatable             | character_data  | <- YES always for BASE TABLE

    // FDO needs a size (length) for types that become strings.
    // For such types that don't allow size to be set, the following query
    // returns the  max length for the type, as size.

    // Length for bit columns is not stored in any of the lenght or precision
    // fields so it is parsed out of column_type, which will have
    // format of bit(n) where n is the number of bits.

    // TODO: mloskot - Currently, if there is no length available for
    // text types, 64 KB is assumed as max text size.
    // Although, in PostgreSQL, the longest possible character string that
    // can be stored is about 1 GB.

    // $1 - name of table

    sql = FdoStringP::Format(
        L" SELECT %ls n.nspname || '.' || r.relname AS table_name, c.attname AS name, 1 AS type,"
	    L" d.adsrc as default_value, \n"
        L" c.atttypmod AS typmod, "
        L" CASE WHEN c.attnotnull THEN 0 ELSE 1 END AS nullable,"
        L" 0 as is_autoincremented, "
        L" lower(t.typname) AS type_string,"
        L" cast (null as text) as geom_type,"
        L" c.attnum as ordinal_position, "
        L" %ls as collate_schema_name, "
        L" %ls as collate_name "
        L" FROM pg_catalog.pg_attribute as c "
        L" JOIN pg_catalog.pg_class r on c.attrelid = r.oid "
        L" JOIN pg_catalog.pg_namespace n on r.relnamespace = n.oid and n.nspname not in ('pg_catalog','information_schema','pg_toast','pg_temp1','pg_toast_temp1') "
        L" JOIN pg_catalog.pg_type t on c.atttypid = t.oid "
        L" $(JOIN_CLAUSE) "
        L" LEFT JOIN pg_catalog.pg_attrdef d ON d.adrelid = r.oid and d.adnum = c.attnum "
        L" where c.attnum > 0 "
        L" $(AND) $(QUALIFICATION) "
        L" ORDER BY collate_schema_name, collate_name, c.attnum ASC",
        (join ? L"distinct" : L""),
        (FdoString*) pgMgr->FormatCollateColumnSql(L"n.nspname"),
        (FdoString*) pgMgr->FormatCollateColumnSql(L"r.relname"),
        static_cast<FdoString*>(columnsTableName)
    );

    FdoSmPhReaderP reader = FdoSmPhRdColumnReader::MakeQueryReader(
        L"",
        owner,
        sql,
        L"n.nspname",
        L"r.relname",
        objectNames,
        join
    );

    return reader;
}
FdoSmPhReaderP FdoSmPhRdMySqlColumnReader::MakeQueryReader(
    FdoSmPhOwnerP owner,
    FdoStringsP objectNames,
    FdoSmPhRdTableJoinP join)
{
    FdoStringP sql;

    FdoStringP ownerName(owner->GetName());

    FdoSmPhMgrP          mgr = owner->GetManager();

    FdoSmPhMySqlOwnerP mqlOwner = owner->SmartCast<FdoSmPhMySqlOwner>();

    // Use temporary table when not selecting all columns for this owner. When repeated selects
    // done against information_schema.columns, it is more efficient to build and use a temporary table.
    FdoStringP           columnsTableName = mqlOwner->GetColumnsTable( join || (objectNames->GetCount() > 0) );

    //mysql> desc INFORMATION_SCHEMA.columns;
    //+--------------------------+--------------+------+-----+---------+-------+
    //| Field                    | Type         | Null | Key | Default | Extra |
    //+--------------------------+--------------+------+-----+---------+-------+
    //| TABLE_CATALOG            | varchar(512) | YES  |     | NULL    |       |<- always NULL
    //| TABLE_SCHEMA             | varchar(64)  | NO   |     |         |       |
    //| TABLE_NAME               | varchar(64)  | NO   |     |         |       |
    //| COLUMN_NAME              | varchar(64)  | NO   |     |         |       |
    //| ORDINAL_POSITION         | bigint(21)   | NO   |     | 0       |       |
    //| COLUMN_DEFAULT           | varchar(64)  | YES  |     | NULL    |       |
    //| IS_NULLABLE              | varchar(3)   | NO   |     |         |       |
    //| DATA_TYPE                | varchar(64)  | NO   |     |         |       |
    //| CHARACTER_MAXIMUM_LENGTH | bigint(21)   | YES  |     | NULL    |       |
    //| CHARACTER_OCTET_LENGTH   | bigint(21)   | YES  |     | NULL    |       |
    //| NUMERIC_PRECISION        | bigint(21)   | YES  |     | NULL    |       |
    //| NUMERIC_SCALE            | bigint(21)   | YES  |     | NULL    |       |
    //| CHARACTER_SET_NAME       | varchar(64)  | YES  |     | NULL    |       |
    //| COLLATION_NAME           | varchar(64)  | YES  |     | NULL    |       |
    //| COLUMN_TYPE              | longtext     | NO   |     |         |       |
    //| COLUMN_KEY               | varchar(3)   | NO   |     |         |       |
    //| EXTRA                    | varchar(20)  | NO   |     |         |       |
    //| PRIVILEGES               | varchar(80)  | NO   |     |         |       |
    //| COLUMN_COMMENT           | varchar(255) | NO   |     |         |       |
    //+--------------------------+--------------+------+-----+---------+-------+

    // FDO needs a size (length) for types that become strings. For such types 
    // that don't allow size to be set, the following query returns the 
    // max length for the type, as size.

    // Length for bit columns is not stored in any of the lenght or precision
    // fields so it is parsed out of column_type, which will have format
    // "bit(n)" where n is the number of bits.

    // Note: the maximum length for longtext is actually 4294967295 but
    // the max length of an FDO Data Property is 2147483647.

    // information_schema tables use the utf8 character set with a 
    // case-insensitive collation. This causes problems with MySQL instances
    // on Linux, where database and table names are case-sensitive.
    // The following query overrides the collations to utf8_bin, which
    // is case-sensitive. 

    sql = FdoStringP::Format (
          L"select %ls table_name, column_name as name, 1 as type,\n"
		  L"COLUMN_DEFAULT as default_value, \n"
          L" CASE lower(data_type) \n"
          L"             WHEN 'tinytext' THEN 255 \n"
          L"             WHEN 'text' THEN 65535 \n"
          L"             WHEN 'mediumtext' THEN 65535 \n"
          L"             WHEN 'longtext' THEN 65535  \n"
          L"             WHEN 'enum' THEN 255  \n"
          L"             WHEN 'set' THEN 255  \n"
          L"             ELSE ifnull(character_octet_length,numeric_precision) \n"
          L" END as size, \n"
          L" numeric_scale as scale,\n"
          L" if(is_nullable='YES',1,0) as nullable,\n"
          L" lower(data_type) as type_string,\n"
          L" instr(column_type,'unsigned') as isunsigned,\n"
		  L" if(extra='auto_increment',1,0) as is_autoincremented,\n"
          L" character_set_name,\n"
          L" column_type as full_type\n"
          L" from %ls $(JOIN_FROM) \n"
          L" $(WHERE) $(QUALIFICATION)"
          L" order by table_name collate utf8_bin, ordinal_position asc",
          join ? L"distinct" : L"",
          (FdoString*) columnsTableName
    );

    FdoSmPhReaderP reader = FdoSmPhRdColumnReader::MakeQueryReader(
        L"",
        mgr,
        sql,
        L"table_schema collate utf8_bin",
        L"table_name collate utf8_bin",
        ownerName,
        objectNames,
        join
    );

    return reader;
}
Exemple #4
0
/* called by GUI */
Icon::Icon(User *user, void *d)
{
  char *infos = (char *) d;
  ifile = NULL;
  ofile = NULL;
  char *action = NULL;
  vref = NULL;
  char icon[URL_LEN];
  *icon = 0;

  /* parameters transmission */
  for (char *pt = strtok(infos, "&"); pt ; pt = strtok(NULL, "&")) {
    if (! stringcmp(pt, "<url=")) { pt = getParam(pt); strcpy(names.url, pt); taken = true; }
    else if (! stringcmp(pt, "<file=")) { pt = getParam(pt); ifile = strdup(pt); }
    else if (! stringcmp(pt, "<ofile=")) { pt = getParam(pt); strcpy(names.url, pt); }
    else if (! stringcmp(pt, "<name=")) { pt = getParam(pt); strcpy(names.named, pt); }
    else if (! stringcmp(pt, "<icon=")) { pt = getParam(pt); strcpy(icon, pt); }
    else if (! stringcmp(pt, "<action=")) { pt = getParam(pt); action = strdup(pt); }
    else if (! stringcmp(pt, "<vref=")) {
      pt = strchr(pt, '=');
      pt++;
      char *p2;
      if ((p2 = strchr(pt, '>'))) *p2 = 0;
      vref = strdup(pt);
    }
  }

  if (vref) {	// local saved document exists
    parser(vref);

    // get the last loaded texture
    int texid = Texture::getIdByUrl(names.url);
    Texture *tclast = Texture::getEntryById(texid);
    if (! tclast) {
      tex = new char[sizeof(ICO_DEF) + 1];
      strcpy(tex, ICO_DEF);	// default texture
    }
    else {
      tex = new char[strlen(tclast->url) + 1];
      strcpy(tex, tclast->url);
    }
    taken = false;
  }

  else {	// new document named interactively by hand
    /* position */
    float off = 0.4;
    pos.x = user->pos.x + off * Cos(user->pos.az);
    pos.y = user->pos.y + off * Sin(user->pos.az);
    pos.z = user->pos.z + 0.6;        // visible by eyes
    pos.az = user->pos.az + M_PI_2;

    /* texture */
    if (*icon) {
      tex = new char[strlen(icon) + 1];
      strcpy(tex, icon);
    }
    else {
      // default binding icon to document
      char ext[8] = "";
      memset(ext, 0, sizeof(ext));
      if (Format::getExt(names.url, ext)) {
        tex = new char[URL_LEN];
        Format::getImgByExt(ext, tex);
      }
      else {
        tex = new char[sizeof(ICO_DEF) + 1];
        strcpy(tex, ICO_DEF);
      }
    }

    if (ifile) {	// private local document
      if (*names.url) {
        // public url given by user
        Cache::download(ifile, ofile, "inout");
      }
      else {
        // build local ofile in ~/public_html/vreng/
        ofile = new char[URL_LEN];
        sprintf(ofile, "%s/public_html", getenv("HOME"));
        if (access(ofile, R_OK|W_OK|X_OK) == 0) {
          strcat(ofile, "/vreng/");
          if (access(ofile, R_OK|W_OK|X_OK) == -1)
            mkdir(ofile, 0755);
          strcat(ofile, ifile);
          FILE *fin, *fout;
          if ((fin = File::openFile(ifile, "r")) && (fout = File::openFile(ofile, "w"))) {
            char buf[2];
            while (fread(buf, 1, 1, fin))
              fwrite(buf, 1, 1, fout);
            File::closeFile(fin);
            File::closeFile(fout);
            chmod(ofile, 0644);

            //FIXME: define local http_server
            sprintf(names.url, "http://%s/~%s/vreng/%s", DEF_HTTP_SERVER, getenv("USER"), ifile);
          }
          else {
            error("can't open %s or %s: %s (%d)", ifile, ofile, strerror(errno), errno);
            free(ifile); ifile = NULL;
            delete[] ofile;
          }
        }
        else {
          error("can't access %s", ofile);
          free(ifile); ifile = NULL;
          delete[] ofile;
        }
      }
    }
    makeSolid();
  }

  // local creation
  defaults();

  enableBehavior(REMOVABLE);
  enableBehavior(NO_ELEMENTARY_MOVE);
  setRenderPrior(RENDER_HIGH);

  initializeMobileObject(1);
  ttl = (taken) ? MAXFLOAT : 0;
  initImposedMovement(ttl);
  disablePermanentMovement();

  // network creation
  createVolatileNetObject(PROPS);

  // document's owner
  setOwner();

  trace(DBG_WO, "Icon: url=%s icon=%s name=%s owner=%s", urlName(), tex, getInstance(), ownerName());

  if (action) {
    if      (! stringcmp(action, "pin")) pin(this, NULL, 0L, 0L);
    else if (! stringcmp(action, "push")) push(this, NULL, 0L, 0L);
    else if (! stringcmp(action, "carry")) carry(this, NULL, 0L, 0L);
  }
}
wxThread::ExitCode PFMMonitorThread::Entry()
{
	const int timeoutMSecs = 50;
	long long startChangeInstance = 0, nextChangeInstance = 0;
	PfmApi *pfmApi = PFMProxy::getInstance().getPfmApi();

	// Get the main frame window
	EncFSMPMainFrame *pMainFrame = NULL;
	wxWindow *pTopWindow = wxTheApp->GetTopWindow();
	if(pTopWindow != NULL)
	{
		pMainFrame = dynamic_cast<EncFSMPMainFrame *>(pTopWindow);
	}

	while(!TestDestroy())
	{
		int retVal = pfmMonitor_->Wait(nextChangeInstance, timeoutMSecs);
		bool sendEvents = true;
		{
			wxMutexLocker lock(mutex_);
			sendEvents = sendEvents_;
		}

		if(sendEvents)
		{
			PfmIterator *iter = NULL;
			pfmApi->MountIterate(startChangeInstance, &nextChangeInstance, &iter);

			long long curChangeInstance = 0;
			int mountId = iter->Next(&curChangeInstance);
			while(mountId > 0)
			{
				if(curChangeInstance >= startChangeInstance)
				{
					PfmMount *curMount = NULL;
					int err = pfmApi->MountIdOpen(mountId, &curMount);

					if(err == 0 && curMount != NULL)
					{
						int statusFlags = curMount->GetStatusFlags();

						std::wstring formatterName(curMount->GetFormatterName());
						std::wstring fileName(curMount->GetMountSourceName());
						wchar_t driveLetter = curMount->GetDriveLetter();
#if !defined(EFS_WIN32)
						driveLetter = L' ';
#endif
						std::wstring ownerName(curMount->GetOwnerName());
						std::wstring ownerId(curMount->GetOwnerId());
						std::wstring mountPoint(curMount->GetMountPoint());

						if(formatterName == EncFSMPStrings::formatterName_)
						{
							if((statusFlags & (pfmStatusFlagReady | pfmStatusFlagDisconnected | pfmStatusFlagClosed)) != 0)
							{
								bool isMountEvent = ((statusFlags & (pfmStatusFlagDisconnected | pfmStatusFlagClosed)) == 0);
								pMainFrame->addNewMountEvent(isMountEvent, false, fileName, driveLetter, mountPoint);
							}
						}

						curMount->Release();
					}
				}
				mountId = iter->Next(&curChangeInstance);
			}

			iter->Release();
			startChangeInstance = nextChangeInstance;
		}
	}

	return 0;
}