zak Tue Jul 15 14:19:51 2003 EDT Modified files: /php-src/ext/dbase php_dbase.h dbase.c Log: Added function dbase_get_header_info * Passed a handle for an open dbase database, it returns an array of associative arrays. Each associative array contains information on a single column, including name, column type, length, precision, ... Index: php-src/ext/dbase/php_dbase.h diff -u php-src/ext/dbase/php_dbase.h:1.12 php-src/ext/dbase/php_dbase.h:1.13 --- php-src/ext/dbase/php_dbase.h:1.12 Tue Jun 10 16:03:27 2003 +++ php-src/ext/dbase/php_dbase.h Tue Jul 15 14:19:51 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dbase.h,v 1.12 2003/06/10 20:03:27 imajes Exp $ */ +/* $Id: php_dbase.h,v 1.13 2003/07/15 18:19:51 zak Exp $ */ #ifndef PHP_DBASE_H #define PHP_DBASE_H @@ -35,6 +35,7 @@ PHP_FUNCTION(dbase_delete_record); PHP_FUNCTION(dbase_pack); PHP_FUNCTION(dbase_get_record_with_names); +PHP_FUNCTION(dbase_get_header_info); #else #define dbase_module_ptr NULL #endif Index: php-src/ext/dbase/dbase.c diff -u php-src/ext/dbase/dbase.c:1.64 php-src/ext/dbase/dbase.c:1.65 --- php-src/ext/dbase/dbase.c:1.64 Tue Jun 10 16:03:27 2003 +++ php-src/ext/dbase/dbase.c Tue Jul 15 14:19:51 2003 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dbase.c,v 1.64 2003/06/10 20:03:27 imajes Exp $ */ +/* $Id: dbase.c,v 1.65 2003/07/15 18:19:51 zak Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -737,8 +737,71 @@ PHP_FE(dbase_get_record_with_names, NULL) PHP_FE(dbase_delete_record, NULL) PHP_FE(dbase_pack, NULL) + PHP_FE(dbase_get_header_info, NULL) {NULL, NULL, NULL} }; +/* }}} */ + +/* Added by Zak Greant <[EMAIL PROTECTED]> */ +/* {{{ proto array dbase_get_header_info(int database_handle) + */ +PHP_FUNCTION(dbase_get_header_info) +{ + zval **dbh_id, *row; + dbfield_t *dbf, *cur_f; + dbhead_t *dbh; + int dbh_type; + DBase_TLS_VARS; + + if (ZEND_NUM_ARGS() != 1 || (zend_get_parameters_ex(1, &dbh_id) == FAILURE)) { + WRONG_PARAM_COUNT; + } + convert_to_long_ex(dbh_id); + + dbh = zend_list_find(Z_LVAL_PP(dbh_id), &dbh_type); + if (!dbh || dbh_type != DBase_GLOBAL(le_dbhead)) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to find database for identifier %d", Z_LVAL_PP(dbh_id)); + RETURN_FALSE; + } + + if (array_init(return_value)==FAILURE) { + RETURN_FALSE; + } + + dbf = dbh->db_fields; + for (cur_f = dbf; cur_f < &dbh->db_fields[dbh->db_nfields]; ++cur_f) { + MAKE_STD_ZVAL(row); + array_init(row); + + add_next_index_zval(return_value, row); + + /* field name */ + add_assoc_string(row, "name", cur_f->db_fname, 1); + + /* field type */ + switch (cur_f->db_type) { + case 'C': add_assoc_string(row, "type", "character", 1); break; + case 'D': add_assoc_string(row, "type", "date", 1); break; + case 'I': add_assoc_string(row, "type", "integer", 1); break; + case 'N': add_assoc_string(row, "type", "number", 1); break; + case 'L': add_assoc_string(row, "type", "boolean", 1); break; + case 'M': add_assoc_string(row, "type", "memo", 1); break; + default: add_assoc_string(row, "type", "unknown", 1); break; + } + + /* length of field */ + add_assoc_long(row, "length", cur_f->db_flen); + + /* number of decimals in field */ + add_assoc_long(row, "decimal places", cur_f->db_fdc); + + /* format for printing %s etc */ + add_assoc_string(row, "printf format", cur_f->db_format, 1); + + /* offset within record */ + add_assoc_long(row, "record offset", cur_f->db_foffset); + } +} /* }}} */ zend_module_entry dbase_module_entry = {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php