Firebird Php Generator Professional Organizer
I'm currently working on modifying a Firebird v. 1.5 database.
The database structure will be modified running queries from a delphi application using interbase components, the problem I'm facing is that I need to run a lot of queries, some of which include creating generators and updating the generator value, the problem is that I need to achieve this in as few queries as possible, but it seems(at least to me) that this is not really possible, what I'm trying to do is the following:
- Mar 28, 2015 Firebird PHP Generator is a freeware but powerful GUI frontend that allows you to generate high-quality Firebird PHP scripts for the selected tables, views and queries for the further working with.
- If you can upgrade to the latest version of Firebird then you could use EXECUTE BLOCK and / or EXECUTE STATEMENT to do it all 'in one statement' and server side, but with Firebird 1.5 you have to settle for the long way (one statement to get the current max, then another one update the generator).
- Declares a set of journalists! Comments; Publications; Comments. Comments; Publications.
So I've created a generator, now I need to set it's value at the current max id from table TABLENAME, like so:
Now, is there any workaround for this, or am I forced to:
Firebird Generator Guide A guide on how and when to use generators in Firebird. Frank Ingermann. 7 May 2006 – Document version 0.2. Table of Contents. Introduction Generator Basics SQL statements for generators Using generators to create unique row IDs What else to do with generators A. Document history B. License notice.
- create the generator
- get the max id
- update the generator value
and repeat process for every table?
I also expected that
would be a workaround to get the max id's from every table in one command, but it doesn't.
bluishFree Php Generator Software
ComputerSaysNo3 Answers
Statement
mixes DDL (SET GENERATOR
) and DML (SELECT
), AFAIK this is not generally supported and Firebird doesn't support it for sure.
If you can upgrade to the latest version of Firebird then you could use EXECUTE BLOCK and / or EXECUTE STATEMENT to do it all 'in one statement' and server side, but with Firebird 1.5 you have to settle for the long way (one statement to get the current max, then another one update the generator).
ainainYou could create a stored procedure and call it from Delphi:
It looks like execute statement
is supported by Firebird 1.5 already.In Firebird 2.0 and later, you could also wrap the code in a execute block
and avoid creating a stored procedure.
With the following trick you can set the generator value to the maximum ID value of a table with one SQL statement in Firebird:
That works, because GEN_ID( <GeneratorName>, <increment>)
gets the generator value and increments it by <increment>
. This should work in Firebird 1.5 as well as in newer versions.
Css Generator
Php Form Generator
Not the answer you're looking for? Browse other questions tagged firebirdauto-incrementfirebird1.5 or ask your own question.
Firebird Php Generator
Here is a minimalistic code example. Be sure to create an user and a database in order to make it work.
<?php
// Minimalistic code example
// Connection
$db = '/path/to/database.gdb';
$user = 'username';
$password = 'password';
$res = ibase_connect($db,$dbuser,$dbpass) or die('<br>' . ibase_errmsg());
// Query
$sql='SELECT * FROM table;'
$result=ibase_query($res,$sql) or die(ibase_errmsg());
while($row=ibase_fetch_object($result)){
// use $row->FIELDNAME not $row->fieldname
print $row->FIELDNAME;
}
ibase_free_result($result);
// Closing
ibase_close($res) or die('<br>' . ibase_errmsg());
?>
The following code can be used when creating tables in order to get auto incrementing fields:
<?php
// This function generates an autoincrement field, such as MySQL AUTO_INCREMENT.
function generate_autoincrement($tablename,$primarykey){
// * Generator
dbexec('CREATE GENERATOR GEN_' . $tablename . '_PK;');
// * Trigger
dbexec('CREATE TRIGGER INC_' . $primarykey . ' FOR ' . $tablename
. chr(13) . 'ACTIVE BEFORE INSERT POSITION 0'
. chr(13) . 'AS'
. chr(13) . 'BEGIN'
. chr(13) . 'IF (NEW.' . $primarykey . ' IS NULL) THEN'
. chr(13) . 'NEW.' . $primarykey . '= GEN_ID(GEN_' . $tablename . '_PK, 1);'
. chr(13) . 'END');
}
?>
Usage: <?php generate_autoincrement('table','column name'); ?>