QgsSpatiaLiteConnection::Error QgsSpatiaLiteConnection::fetchTables( bool loadGeometrylessTables ) { mErrorMsg = QString(); QFileInfo fi( mPath ); if ( !fi.exists() ) { return NotExists; } sqlite3* handle = openSpatiaLiteDb( fi.canonicalFilePath() ); if ( handle == NULL ) { return FailedToOpen; } checkHasMetadataTables( handle ); if ( !mErrorMsg.isNull() ) { // unexpected error; invalid SpatiaLite DB return FailedToCheckMetadata; } if ( !getTableInfo( handle, loadGeometrylessTables ) ) { return FailedToGetTables; } closeSpatiaLiteDb( handle ); return NoError; }
int CMibHPTable::getFirstIndex(index_info_T* index) { index->index_number = getTableInfo()->table_index_num; index->index[0] = CCommonDefine::uiConstDeviceIndex; PairRscVC4* p = PairRscVC4::getFirstInstance(); if( p ) { index->index[1] = (p->getUID() >> 24) + 1; index->index[2] = p->getUID(); return 1; } return -1; }
int CMibVFPortTable::getNextIndex(index_info_T* index) { index->index_number = getTableInfo()->table_index_num; index->index[0] = CCommonDefine::uiConstDeviceIndex; PortVF* p = PortVF::getNextInstance(index->index[2]); if( p ) { uint32 uid = p->getUID(); index->index[1] = (uid >> 24) + 1; index->index[2] = uid; return 1; } return -1; }
bool SQLite::updateTableCell(const QString &db, const QString &table, const QString &column, int rowid, const QVariant &data, int &rc) { QSharedPointer<SQLiteTableInfo> pTableInfo = getTableInfo(table, rc); if (pTableInfo.isNull()) { return false; } bool hasAffinity; for(int i = 0; i < pTableInfo->size(); i++) { if (pTableInfo->getColumnName(i).compare(column) == 0) { hasAffinity = pTableInfo->hasAffinity(i); } } QString updateQuery = tr("update '%1'.'%2' set %3=? where rowid=%4") .arg(db) .arg(table) .arg(column) .arg(rowid); QSharedPointer<SQLiteStmt> pStmt = prepare(updateQuery, rc); if (pStmt.isNull()) { return false; } bool isBound = false; if (data.type() == QVariant::UserType) { isBound = pStmt->bindNull(1, rc); } else { // If there is no column affinity, we should try to intelligently bind to the // right type. If there is column affinity, we will simply bind as text, and // let SQLite figure out the appropriate storage container. if (hasAffinity) { isBound = pStmt->bindText(1, data.toString(), rc); } else { isBound = pStmt->bindConvert(1, data.toString(), rc); } } if (!isBound) { return false; } pStmt->step(rc); if (SQLITE_DONE != rc) { return false; } return true; }
void QgsSpatiaLiteSourceSelect::on_btnConnect_clicked() { sqlite3 *handle; QSettings settings; QString subKey = cmbConnections->currentText(); int idx = subKey.indexOf( "@" ); if ( idx > 0 ) subKey.truncate( idx ); QFileInfo fi( settings.value( QString( "/SpatiaLite/connections/%1/sqlitepath" ).arg( subKey ) ).toString() ); if ( !fi.exists() ) // db doesn't exists return; // trying to connect to SpatiaLite DB handle = openSpatiaLiteDb( fi.canonicalFilePath() ); if ( handle == NULL ) { // unexpected error; invalid SpatiaLite DB return; } QModelIndex rootItemIndex = mTableModel.indexFromItem( mTableModel.invisibleRootItem() ); mTableModel.removeRows( 0, mTableModel.rowCount( rootItemIndex ), rootItemIndex ); // populate the table list // get the list of suitable tables and columns and populate the UI geomCol details; if ( !getTableInfo( handle ) ) { QgsDebugMsg( QString( "Unable to get list of spatially enabled tables from the database\n%1" ).arg( sqlite3_errmsg( handle ) ) ); } closeSpatiaLiteDb( handle ); if ( cmbConnections->count() > 0 ) mAddButton->setEnabled( true ); mTablesTreeView->sortByColumn( 0, Qt::AscendingOrder ); //expand all the toplevel items int numTopLevelItems = mTableModel.invisibleRootItem()->rowCount(); for ( int i = 0; i < numTopLevelItems; ++i ) { mTablesTreeView->expand( mProxyModel.mapFromSource( mTableModel.indexFromItem( mTableModel.invisibleRootItem()->child( i ) ) ) ); } mTablesTreeView->resizeColumnToContents( 0 ); mTablesTreeView->resizeColumnToContents( 1 ); }
bool QgsPostgresConn::supportedLayers( QVector<QgsPostgresLayerProperty> &layers, bool searchGeometryColumnsOnly, bool searchPublicOnly, bool allowGeometrylessTables ) { // Get the list of supported tables if ( !getTableInfo( searchGeometryColumnsOnly, searchPublicOnly, allowGeometrylessTables ) ) { QgsMessageLog::logMessage( tr( "Unable to get list of spatially enabled tables from the database" ), tr( "PostGIS" ) ); return false; } layers = mLayersSupported; QgsDebugMsg( "Exiting." ); return true; }
QgsSpatiaLiteConnection::Error QgsSpatiaLiteConnection::fetchTables( bool loadGeometrylessTables ) { mErrorMsg = QString(); QFileInfo fi( mPath ); if ( !fi.exists() ) return NotExists; sqlite3 *handle = openSpatiaLiteDb( fi.canonicalFilePath() ); if ( !handle ) return FailedToOpen; int ret = checkHasMetadataTables( handle ); if ( !mErrorMsg.isNull() || ret == LayoutUnknown ) { // unexpected error; invalid SpatiaLite DB return FailedToCheckMetadata; } bool recentVersion = false; #ifdef SPATIALITE_VERSION_GE_4_0_0 // only if libspatialite version is >= 4.0.0 recentVersion = true; #endif if ( ret == LayoutCurrent && !recentVersion ) { // obsolete library version mErrorMsg = tr( "obsolete libspatialite: connecting to this DB requires using v.4.0 (or any subsequent)" ); return FailedToCheckMetadata; } #ifdef SPATIALITE_VERSION_GE_4_0_0 // only if libspatialite version is >= 4.0.0 // using v.4.0 Abstract Interface if ( !getTableInfoAbstractInterface( handle, loadGeometrylessTables ) ) #else // obsolete library: still using the traditional approach if ( !getTableInfo( handle, loadGeometrylessTables ) ) #endif { return FailedToGetTables; } closeSpatiaLiteDb( handle ); return NoError; }
bool SQLite::insertTableRow(const QString &db, const QString &table, const QStringList &row, int &rc) { QString insertQuery = tr("insert into '%1'.'%2' values (").arg(db).arg(table); QStringList bindParams; for (int i = 0; i < row.size(); i++) { bindParams += tr("?"); } insertQuery.append(bindParams.join(",")).append(")"); QSharedPointer<SQLiteTableInfo> pTableInfo = getTableInfo(table, rc); if (pTableInfo.isNull()) { return false; } QSharedPointer<SQLiteStmt> pStmt = prepare(insertQuery, rc); if (pStmt.isNull()) { return false; } for (int i = 0; i < row.size(); i++) { bool isBound; if (row.at(i).isNull()) { isBound = pStmt->bindNull(i + 1, rc); } else if (pTableInfo->hasAffinity(i)) { isBound = pStmt->bindText(i + 1, row.at(i), rc); } else { isBound = pStmt->bindConvert(i + 1, row.at(i), rc); } if (!isBound) { return false; } } pStmt->step(rc); if (SQLITE_DONE != rc) { return false; } return true; }
std::vector< std::pair<uint64_t,uint64_t> > getTable() const { libmaus2::aio::InputStreamInstance ISI(indexfn); std::pair<uint64_t,uint64_t> const P = getTableInfo(ISI); ISI.clear(); ISI.seekg(P.first,std::ios::beg); std::vector< std::pair<uint64_t,uint64_t> > V; for ( uint64_t i = 0; i < P.second; ++i ) { uint64_t const a = libmaus2::util::NumberSerialisation::deserialiseNumber(ISI); uint64_t const b = libmaus2::util::NumberSerialisation::deserialiseNumber(ISI); V.push_back(std::pair<uint64_t,uint64_t>(a,b)); } return V; }
struct pslReader *pslReaderQuery(struct sqlConnection* conn, char* table, char* where) /* Create a new pslReader to read from the given table in the database. * If where is not null, it is added as a where clause. It will determine if * pslx columns are in the table. */ { char query[1024]; struct pslReader* pr; AllocVar(pr); pr->table = cloneString(table); if (where != NULL) sqlSafef(query, sizeof(query), "select * from %s where %s", table, where); else sqlSafef(query, sizeof(query), "select * from %s", table); pr->sr = sqlGetResult(conn, query); getTableInfo(pr); return pr; }
struct pslReader *pslReaderChromQuery(struct sqlConnection* conn, char* table, char* chrom, char* extraWhere) /* Create a new pslReader to read all rows for a chrom in a database table. * If extraWhere is not null, it is added as an additional where condition. It * will determine if pslx columns are in the table. */ { struct pslReader* pr; int rowOffset; AllocVar(pr); pr->table = cloneString(table); /* non-existant table will return null */ pr->sr = hChromQuery(conn, table, chrom, extraWhere, &rowOffset); if (pr->sr != NULL) getTableInfo(pr); assert(pr->rowOffset == rowOffset); return pr; }
/* * printTableInfo -- テーブルのデータ定義情報を表示する(動作確認用) * * 引数: * tableName: 情報を表示するテーブルの名前 * * 返り値: * なし */ void printTableInfo(char *tableName) { TableInfo *tableInfo; int i; /* テーブル名を出力 */ printf("\nTable %s\n", tableName); /* テーブルの定義情報を取得する */ if ((tableInfo = getTableInfo(tableName)) == NULL) { /* テーブル情報の取得に失敗したので、処理をやめて返る */ return; } /* フィールド数を出力 */ printf("number of fields = %d\n", tableInfo->numField); /* フィールド情報を読み取って出力 */ for (i = 0; i < tableInfo->numField; i++) { /* フィールド名の出力 */ printf(" field %d: name = %s, ", i + 1, tableInfo->fieldInfo[i].name); /* データ型の出力 */ printf("data type = "); switch (tableInfo->fieldInfo[i].dataType) { case TYPE_INTEGER: printf("integer\n"); break; case TYPE_STRING: printf("string\n"); break; default: printf("unknown\n"); } } /* データ定義情報を解放する */ freeTableInfo(tableInfo); return; }
/* * callDeleteRecord -- delete文の構文解析とdeleteRecordの呼び出し * * 引数: * なし * * 返り値: * なし * * deleteの書式: * delete from テーブル名 where 条件式 */ void callDeleteRecord() { char *token; char *tableName; Condition condition; TableInfo *tableInfo; int i; /*deleteの次のトークンを読み込み、それが"from"かどうかをチェック */ token = getNextToken(); if (token == NULL || strcmp(token, "from") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } /* テーブル名を読み込む */ if ((tableName = getNextToken()) == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", tableName); return; } /*次のトークンを読み込み、それが"where"かどうかをチェック */ token = getNextToken(); if (token == NULL || strcmp(token, "where") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } /* 条件式のフィールド名を読み込む */ if ((token = getNextToken()) == NULL){ /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } strcpy(condition.name, token); /* テーブルの情報を取得する */ if ((tableInfo = getTableInfo(tableName)) == NULL) { /* エラー処理 */ return; } /*条件式に指定されたフィールドのデータ型を調べる*/ condition.dataType = TYPE_UNKNOWN; for (i = 0; i < tableInfo->numField; i++){ if (strcmp(tableInfo->fieldInfo[i].name, condition.name) == 0){ /* データ型をconditionにコピーしてループからぬける*/ condition.dataType = tableInfo->fieldInfo[i].dataType; break; } } freeTableInfo(tableInfo); /*conditionを決定する*/ conditionSet(token, &condition); /* dereteRecordを呼び出し、レコードを削除 */ if (deleteRecord(tableName, &condition) == OK) { printf("レコードを削除しました。\n"); } else { printf("レコードの削除に失敗しました。\n"); } }
int TableClockSourceOption::getFirstIndex(index_info_T* index) { index->index_number = getTableInfo()->table_index_num; index->index[0] = CCommonDefine::uiConstDeviceIndex; return 1; }
void SaSourceSelect::on_btnConnect_clicked() { if ( mColumnTypeThread ) { mColumnTypeThread->stop(); mColumnTypeThread = 0; } QModelIndex rootItemIndex = mTableModel.indexFromItem( mTableModel.invisibleRootItem() ); mTableModel.removeRows( 0, mTableModel.rowCount( rootItemIndex ), rootItemIndex ); // populate the table list QSettings settings; // load the SQL Anywhere interface if ( !SqlAnyConnection::initApi() ) { QMessageBox::information( this, tr( "Failed to load interface" ), tr( SqlAnyConnection::failedInitMsg() ) ); return; } // compute connection information QString key = "/SQLAnywhere/connections/" + cmbConnections->currentText(); mEstimateMetadata = settings.value( key + "/estimateMetadata", false ).toBool(); mOtherSchemas = settings.value( key + "/otherSchemas", false ).toBool(); mConnInfo = SqlAnyConnection::makeUri( key , settings.value( key + "/host" ).toString() , settings.value( key + "/port" ).toString() , settings.value( key + "/server" ).toString() , settings.value( key + "/database" ).toString() , settings.value( key + "/parameters" ).toString() , settings.value( key + "/username" ).toString() , settings.value( key + "/password" ).toString() , settings.value( key + "/simpleEncryption", false ).toBool() , mEstimateMetadata ); SaDebugMsg( "Connection info: " + mConnInfo ); // establish read-only connection to the database char errbuf[SACAPI_ERROR_SIZE]; sacapi_i32 code; SqlAnyConnection *conn = SqlAnyConnection::connect( mConnInfo, true, code, errbuf, sizeof( errbuf ) ); if ( conn ) { // get the list of suitable tables and columns and populate the UI geomCol details; if ( getTableInfo( conn->addRef(), mOtherSchemas ) ) { // Start the thread that gets the geometry type for relations that // may take a long time to return if ( mColumnTypeThread != NULL ) { connect( mColumnTypeThread, SIGNAL( setLayerType( QString, QString, QString, QString, QString, QString ) ), this, SLOT( setLayerType( QString, QString, QString, QString, QString, QString ) ) ); // Do it in a thread. mColumnTypeThread->start(); } } else { SaDebugMsg( "Unable to get list of spatially enabled tables " "from the database" ); } if ( cmbConnections->count() > 0 ) mAddButton->setEnabled( true ); conn->release(); } else { QMessageBox::warning( this, tr( "Connection failed" ), tr( "Connection to database %1 failed. " "Check settings and try again.\n\n" "SQL Anywhere error code: %2\n" "Description: %3" ) .arg( settings.value( key + "/database" ).toString() ) .arg( code ) .arg( errbuf ) ); } mTablesTreeView->sortByColumn( SaDbTableModel::dbtmTable, Qt::AscendingOrder ); mTablesTreeView->sortByColumn( SaDbTableModel::dbtmSchema, Qt::AscendingOrder ); //if we have only one schema item, expand it by default int numTopLevelItems = mTableModel.invisibleRootItem()->rowCount(); if ( numTopLevelItems < 2 || mTableModel.tableCount() < 20 ) { //expand all the toplevel items for ( int i = 0; i < numTopLevelItems; ++i ) { mTablesTreeView->expand( mProxyModel.mapFromSource( mTableModel.indexFromItem( mTableModel.invisibleRootItem()->child( i ) ) ) ); } } }
/* * callInsertRecord -- insert文の構文解析とinsertRecordの呼び出し * * 引数: * なし * * 返り値: * なし * * insertの書式: * insert into テーブル名 values ( フィールド値 , ... ) */ void callInsertRecord() { char *token; char *tableName; int numField; RecordData *recordData; TableInfo *tableInfo; int i; /*insertの次のトークンを読み込み、それが"into"かどうかをチェック */ token = getNextToken(); if (token == NULL || strcmp(token, "into") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } /* テーブル名を読み込む */ if ((tableName = getNextToken()) == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", tableName); return; } /* 次のトークンを読み込み、それが"values"かどうかをチェック */ token = getNextToken(); if (token == NULL || strcmp(token, "values") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); return; } /* 次のトークンを読み込み、それが"("かどうかをチェック */ token = getNextToken(); if (token == NULL || strcmp(token, "(") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); return; } /* テーブルの情報を取得する */ if ((tableInfo = getTableInfo(tableName)) == NULL) { /* エラー処理 */ return; } /*RecordData構造体のメモリを確保*/ if ((recordData = (RecordData *)malloc(sizeof(RecordData))) == NULL){ fprintf(stderr, "Malloc error.\n"); return; } numField = 0; for (i = 0; i < tableInfo->numField; i++) { /* フィールド名の読み込み */ if ((token = getNextToken()) == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); freeTableInfo(tableInfo); return; } switch (tableInfo->fieldInfo[i].dataType) { case TYPE_INTEGER: recordData->fieldData[i].intValue = atoi(token); break; case TYPE_STRING: strcpy(recordData->fieldData[i].stringValue, token); break; default: freeTableInfo(tableInfo); return; } numField++; /* 次のトークンの読み込み */ token = getNextToken(); if (token == NULL){ /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); freeTableInfo(tableInfo); return; } if (strcmp(token, ")") == 0){ /*ループから出る*/ break; } else if (strcmp(token, ",") == 0) { /* 次のフィールドを読み込むため、ループの先頭へ */ continue; } else { /* 文法エラー */ printf("入力行に間違いがあります。\n"); freeTableInfo(tableInfo); return; } } if (numField != tableInfo->numField){ return; } freeTableInfo(tableInfo); /* insertRecordを呼び出し、レコードを挿入 */ if (insertRecord(tableName, recordData) == OK) { printf("レコードを挿入しました。\n"); } else { printf("レコードの挿入に失敗しました。\n"); } free(recordData); }
/* * callSelectRecord -- select文の構文解析とselectRecordの呼び出し * * 引数: * なし * * 返り値: * なし * * selectの書式: * select * from テーブル名 where 条件式 * select フィールド名 , ... from テーブル名 where 条件式 (発展課題) */ void callSelectRecord() { char *token; char *tableName; char *selectField; char *p; Condition condition; TableInfo *tableInfo; RecordSet *recordSet; int i, j; int numField; int allSelectFlag; /* *かどうかの判断 */ char sendFieldName[MAX_FIELD][MAX_FIELD_NAME]; for (i = 0; i < MAX_FIELD; i++){ memset(&sendFieldName[i], '\0', MAX_FIELD_NAME); } /*selectの次のトークンを読み込み、distinctが存在するかをチェック */ token = getNextToken(); if (token == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } if (strcmp(token, "distinct") == 0){ condition.distinct = DISTINCT; /*次のトークンを読み込み、それが"*"かどうかをチェック */ token = getNextToken(); if (token == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } } else{ condition.distinct = NOT_DISTINCT; } selectField = (char *)malloc(sizeof(char)*MAX_FIELD_NAME*MAX_FIELD); p = selectField; numField = 0; if (strcmp(token, "*") != 0){ allSelectFlag = 0; for (;;) { memcpy(p, token, strlen(token) + 1); p += strlen(token); /* フィールド数をカウントする */ numField++; /* 次のトークンの読み込み */ if ((token = getNextToken()) == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); return; } /* 読み込んだトークンが"from"だったら、ループから抜ける */ if (strcmp(token, "from") == 0) { break; } else if (strcmp(token, ",") == 0) { token = " "; memcpy(p, token, strlen(token) + 1); p += strlen(token); /* 次のトークンの読み込み */ if ((token = getNextToken()) == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); return; } continue; } else { /* 文法エラー */ printf("入力行に間違いがあります。%s\n", token); return; } } } /* *だったら */ else if (strcmp(token, "*") == 0){ allSelectFlag = 1; token = getNextToken(); if (strcmp(token, "from") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } } /* テーブル名を読み込む */ if ((tableName = getNextToken()) == NULL) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", tableName); return; } /*次のトークンを読み込み、それが"where"かどうかをチェック */ token = getNextToken(); /*条件が入力されなかったらすべてのレコードを表示*/ if (token == NULL) { /* テーブルの情報を取得する */ if ((tableInfo = getTableInfo(tableName)) == NULL) { /* エラー処理 */ return; } numField = tableInfo->numField; printTableData(tableName, numField); freeTableInfo(tableInfo); free(selectField); return; } if (strcmp(token, "where") != 0) { /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } /* 条件式のフィールド名を読み込む */ if ((token = getNextToken()) == NULL){ /* 文法エラー */ printf("入力行に間違いがあります。:%s\n", token); return; } strcpy(condition.name, token); /* テーブルの情報を取得する */ if ((tableInfo = getTableInfo(tableName)) == NULL) { /* エラー処理 */ return; } /*条件式に指定されたフィールドのデータ型を調べる*/ condition.dataType = TYPE_UNKNOWN; for (i = 0; i < tableInfo->numField; i++){ if (strcmp(tableInfo->fieldInfo[i].name, condition.name) == 0){ /* データ型をconditionにコピーしてループからぬける*/ condition.dataType = tableInfo->fieldInfo[i].dataType; break; } } /*conditionを決定する*/ conditionSet(token, &condition); /* selectRecordを呼び出し、レコードを検索 */ if ((recordSet = selectRecord(tableName, &condition)) == NULL) { printf("レコードの検索に失敗しました。\n"); } /*selectFieldがフィールド名にあるか調べる*/ if (allSelectFlag == 0){ setInputString(selectField); token = getNextToken(); for (i = 0; i < MAX_FIELD; i++){ if (token == NULL){ break; } for (j = 0; j < tableInfo->numField; j++){ /*tokenがフィールド名と一致したら*/ if (strcmp(tableInfo->fieldInfo[j].name, token) == 0){ strcpy(sendFieldName[i], token); token = getNextToken(); break; } if (j == tableInfo->numField - 1){ printf("そのフィールド名は存在しません%s\n", token); return; } } } } /* *の場合は */ else{ for (i = 0; i < tableInfo->numField; i++){ strcpy(sendFieldName[i], tableInfo->fieldInfo[i].name); } numField = tableInfo->numField; } /*検索したレコード集合を表示*/ printRecordSet(recordSet, sendFieldName, numField); /*解放*/ free(selectField); freeTableInfo(tableInfo); freeRecordSet(recordSet); }
/* * reading a TrueType font * calling functions for 'name', 'EBLC', 'EBDT' tables */ int main(int argc, char **argv){ uchar *ttfL; //on memory location: top of TrueTypeFile char copyright[MAXSTRINGINBDF] = STRUNKNOWN; char fontname[MAXSTRINGINBDF] = STRUNKNOWN; if(argc!=2){ fprintf(stderr, PROGNAME " version " PROGVERSION " - extract bitmap-data from a TrueType font\n"); fprintf(stderr, "usage: " PROGNAME " file.ttf\n"); exit(1); } /* * reading TrueTypeFile to Memory */ { FILE *fp; size_t ttfsize; struct stat info; if((fp=fopen(argv[1],"rb"))==NULL) errexit("cannot open '%s'", argv[1]); if(stat(argv[1], &info) != 0) errexit("stat"); ttfsize = info.st_size; if((ttfL=malloc(ttfsize))==NULL) errexit("malloc"); if(fread(ttfL, 1, ttfsize, fp)!=ttfsize) errexit("fread"); fclose(fp); } //ckeck this file is TrueType? or not validiateTTF(ttfL); { tableinfo table; //store the first table //dynamically allocate second and after tables tableinfo *t; //loop uchar *eblcL = NULL; //on memory location: top of EBLC table uchar *ebdtL = NULL; //on memory location: top of EBDT table //get locations of tables getTableInfo(ttfL, &table); /* * reading name table * get strings of copyright, fontname */ for(t=table.next; t->next!=NULL; t=t->next){ if(strcmp("name", t->tag)==0){ see_name(ttfL + t->offset, copyright, fontname); break; } } //EBDT table for(t=table.next; t->next!=NULL; t=t->next){ if(strcmp("EBDT", t->tag)==0 || strcmp("bdat", t->tag)==0) ebdtL = ttfL + t->offset; } if(ebdtL == NULL) errexit("This font has no bitmap-data."); // EBLC table for(t=table.next; t->next!=NULL; t=t->next){ if(strcmp("EBLC", t->tag)==0 || strcmp("bloc", t->tag)==0) eblcL = ttfL + t->offset; } if(eblcL == NULL) errexit("This font has no bitmap-data."); see_eblc(eblcL, ebdtL, copyright, fontname); } exit(EXIT_SUCCESS); }
void Database::indexCreate(IndexDefinition &indexDef) { if(indexDef.getColumnCount() < 1 || indexDef.getColumnCount() >= MAXKEYFIELDCOUNT) { /* must be < MAXKEYFIELDCOUNT because there has to be DbAddr at the end */ throwSqlError(SQL_KEY_TOO_BIG,_T("Invalid columncount (=%d)"),indexDef.getColumnCount()); } if(indexDef.getIndexType() != INDEXTYPE_PRIMARY && indexDef.getIndexType() != INDEXTYPE_UNIQUE && indexDef.getIndexType() != INDEXTYPE_NON_UNIQUE) { throwSqlError(SQL_INVALID_INDEXTYPE,_T("Invalid indextype (=%d)"),indexDef.getIndexType()); } if(indexDef.m_fileName.length() == 0) { indexDef.m_fileName = getNewFileName(_T("KEY")); } if(indexDef.m_indexName.length() == 0) { if(indexDef.getIndexType() == INDEXTYPE_PRIMARY) { indexDef.m_indexName = indexDef.m_tableName; } else { throwSqlError(SQL_INVALID_INDEXNAME,_T("Invalid indexname:<%s>"),indexDef.m_indexName.cstr()); } } if(DbFile::exist(indexDef.m_fileName)) { throwSqlError(SQL_FILE_ALREADY_EXIST,_T("File <%s> already exist"),indexDef.m_fileName.cstr()); } indexDef.m_tableName = toUpperCase(indexDef.m_tableName); indexDef.m_indexName = toUpperCase(indexDef.m_indexName); indexDef.m_fileName = toUpperCase(indexDef.m_fileName); const TableDefinition &tableDef = getTableDefinition(indexDef.m_tableName); if(tableDef.getTableType() != TABLETYPE_USER) { throwSqlError(SQL_INVALID_TABLETYPE,_T("Invalid tabletype (=%c)"),tableDef.getTableType()); } /* check that the indexname is not already used */ KeyFile indexfile2(*this,SYSTEM_INDEXKEY2_FNAME, DBFMODE_READWRITE); KeyFileDefinition keydef2(indexfile2); KeyType key2; keydef2.put(key2,0,indexDef.m_indexName ); if(indexfile2.searchMin(RELOP_EQ, key2, 1)) { throwSqlError(SQL_INDEX_ALREADY_EXIST,_T("Index <%s> already exist"),indexDef.m_indexName.cstr()); } if(!inTMF()) { throwSqlError(SQL_NO_TRANSACTION,_T("indexCreate:No active tmf")); } KeyFileDefinition keydef = tableDef.getKeyFileDefinition(indexDef); KeyFile::create(indexDef.m_fileName, keydef); try { KeyFile keyFile( indexDef.m_fileName, DBFMODE_READWRITE, false); DataFile datafile(tableDef.getFileName(), DBFMODE_READONLY , false); const TableInfo &tableInfo = getTableInfo(tableDef.getTableName()); /* TODO Lock datafile to avoid new records to be inserted */ if(indexDef.getIndexType() != INDEXTYPE_PRIMARY) { dataFileScan(indexDef.m_tableName, KeyGenerator(*this, keyFile, indexDef, tableInfo, keydef)); } sysTabIndexInsert(indexDef); /* TODO Invalidate all binded program-packages; Unlock datafile */ } catch(sqlca) { DbFile::destroy(indexDef.m_fileName); throw; } removeFromCache(indexDef.m_tableName); }