コード例 #1
0
ファイル: ogrgmelayer.cpp プロジェクト: samalone/gdal-ios
OGRErr OGRGMELayer::CreateFeature( OGRFeature *poFeature )

{
    if (!poFeature)
        return OGRERR_FAILURE;
    if (!CreateTableIfNotCreated()) {
        return OGRERR_FAILURE;
    }

    long nFID = ++m_nFeaturesRead;
    poFeature->SetFID(nFID);

    int nGxId = poFeature->GetFieldIndex("gx_id");
    CPLDebug("GME", "gx_id is field %d", iGxIdField);
    CPLString osGxId;
    CPLDebug("GME", "Inserting feature %ld as %s", poFeature->GetFID(), osGxId.c_str());
    if (nGxId >= 0) {
        iGxIdField = nGxId;
        if(poFeature->IsFieldSet(iGxIdField)) {
          osGxId = poFeature->GetFieldAsString(iGxIdField);
          CPLDebug("GME", "Feature already has %ld gx_id='%s'", poFeature->GetFID(),
                   osGxId.c_str());
        }
        else {
            osGxId = CPLSPrintf("GDAL-%ld", nFID);
            CPLDebug("GME", "Setting field %d as %s", iGxIdField, osGxId.c_str() );
            poFeature->SetField( iGxIdField, osGxId.c_str() );
        }
    }

    if (bInTransaction) {
        unsigned int iBatchSize = GetBatchPatchSize();
        if (omnpoInsertedFeatures.size() >= iBatchSize) {
            CPLDebug("GME", "BatchInsert, reached BatchSize of %d", iBatchSize);
            OGRErr iBatchInsertResult = BatchInsert();
            if (iBatchInsertResult != OGRERR_NONE) {
                return iBatchInsertResult;
            }
        }
        omnosIdToGMEKey[poFeature->GetFID()] = osGxId;
        omnpoInsertedFeatures[nFID] = poFeature->Clone();
        CPLDebug("GME", "In Transaction, added feature to memory only");
        bDirty = true;
        return OGRERR_NONE;
    }
    else {
        CPLDebug("GME", "Not in Transaction, BatchInsert()");
        return BatchInsert();
    }
}
コード例 #2
0
ファイル: ogrgmelayer.cpp プロジェクト: samalone/gdal-ios
OGRErr OGRGMELayer::SyncToDisk()

{
    CPLDebug("GME", "SyncToDisk()");
    if (bDirty) {
        if (omnpoInsertedFeatures.size() > 0) {
            BatchInsert();
        }
        if (omnpoUpdatedFeatures.size() > 0) {
            BatchPatch();
        }
        if (oListOfDeletedFeatures.size() > 0) {
            BatchDelete();
        }
        bDirty = false;
    }
    return OGRERR_NONE;
}
コード例 #3
0
void main(int argc, char ** argv)
{
	SQLHANDLE	henv;
	SQLHANDLE	hdbc;
	SQLHANDLE	hstmt;

	char	username[256];
	char	password[256];
	char	datasource[256];
	unsigned int		i,
		j;
  
	char	TableName[50];

	strcpy(datasource, "SQLServer Express");
	//strcpy(datasource, "Microsoft SQL Server");
	strcpy(username, "test");
	strcpy(password, "test");
	strcpy(TableName, "EMPLOYEES_PERFTEST");


  
/*	if (argc < 2) {
		fprintf (stderr, "Usage: ODBCBatchUpdates username/password@datasource\n\n");
		exit(255);
	}
*/

/*	if (getLoginInfo(argv[1], username, password, datasource) != SQL_SUCCESS) {
		fprintf (stderr, "Error: ' %s ' invalid login\n", argv[1]);
		fprintf (stderr, "Usage: ODBCBatchInserts username/password@datasource\n\n");
		exit(255);
	}
*/  
	printf("ODBC BATCH UPDATE TEST\n\n");

	InitODBCEnv(&henv);
	ODBCConnect(henv, &hdbc, username, password, datasource);
	InitODBCStmt(hdbc, &hstmt);

	printf("\nSETTING UP ENVIRONMENT\n");
	printf("Dropping table: %s\n", TableName);
	DropTable(hstmt, TableName);

	printf("Creating table: %s\n", TableName);
	CreateTable(hstmt, TableName);

	printf("Filling table: %s\n", TableName);
	BatchInsert(hdbc, hstmt, TableName, 100, 5000);

	/*	printf("\n\n");
	printf ("Deleting contents of table");
	ClearTable(hstmt, TableName);
	*/
	printf("\n\n");
	PrintTableHeader();

	for (i = 0; i < BatchSizeLen; i++) {
		for (j = 0; j < NumRecUpdatedLen; j++) {
            BatchUpdate(hdbc, hstmt, TableName, BatchSize[i], NumRecUpdated[j]);
			printf("	resetting test...");
			ClearTable(hstmt, TableName);
			BatchInsert(hdbc, hstmt, TableName, 100, 5000);
			printf("done\n");
		}
		printf ("\n");
	}

    Terminate(henv, hdbc, hstmt);

	printf("ODBC BATCH UPDATE TEST COMPLETED.\n\n");
	printf("===========================================================\n");
	printf("Press ENTER to end program...");
	getchar();

}