PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: =?iso-8859-1?Q?Pochet_Fr=E9d=E9ric?= <Frederic dot Pochet at cockerill-sambre dot com>
Subject: TR: Inserting Duplicate Records Message
Date: Jun 28 1999 10:23AM


> ----------
> De : 	Pochet Frédéric
> Date :	lundi 28 juin 1999 10:58
> A :	'jrisley@fedex.com'
> Objet :	RE: Inserting Duplicate Records Message
> 
> Use de callback routines like this:
> 
> 	Your code
> 
> 	ct_callback(CS_CLIENTMSG_CB, \&client_cb);
> 	ct_callback(CS_SERVERMSG_CB, "srv_cb");
> 
> 	##my($dbh)= new Sybase::CTlib  $user, $pwd, $server;
> 	## As Michael say in a previous mail,
> 	## use your My::SybLib to know your sql code in the callback
> routines
> 	## if you don't need to know it, don't use it
> 	## if you want to use it, see the example package below.
> 
> 	my($dbh)= new My::SybLib  $user, $pwd, $server;
> 
> 	your code
> 
> 
> 	sub client_cb {
> 	    my($layer, $origin, $severity, $number, $msg, $osmsg, $dbh) =
> @_;
> 	    
> 	    printf STDERR "\nOpen Client Message: (In msg_cb)\n";
> 	    printf STDERR "Message number: LAYER = (%ld) ORIGIN = (%ld) ",
> 	    $layer, $origin;
> 	    printf STDERR "SEVERITY = (%ld) NUMBER = (%ld)\n",
> 	    $severity, $number;
> 	    printf STDERR "Message String: %s\n", $msg;
> 	    if (defined($osmsg)) {
> 		printf STDERR "Operating System Error: %s\n", $osmsg;
> 	    }
> 	    
> 	    CS_SUCCEED;
> 	}
> 
> 	sub srv_cb {
> 	    my($dbh, $number, $severity, $state, $line, $server,
> 	       $proc, $msg) = @_;
> 	    
> 	    # If $dbh is defined, then you can set or check attributes
> 	    # in the callback, which can be tested in the main body
> 	    # of the code.
> 	    
> 	    #Server message:
> 	    #Message number: 2601, Severity 14, State 3, Line 11, Procedure
> 'xxx'
> 	    #Message String: Attempt to insert duplicate key row in object
> 'f1' 
> 	    #with unique index 'pkf1'
> 	    if ($number == 2601 && $severity == 14 && $state == 3) {
> 		return CS_SUCCEED;
> 	    }
> 	 
> 	#Server message: (In srv_cb)
> 	#Message number: 3621, Severity 10, State 0, Line 11
> 	# Procedure 'iuf1'
> 	#Message String: Command has been aborted.
> 	    elsif (($number, $severity, $state)==(3621,10,0)) {
> 		return CS_SUCCEED;
> 	    }
> 
> 	#Server message: (In srv_cb)
> 	#Message number: 0, Severity 10, State 1, Line 168
> 	# Procedure 'sp_helpkey'
> 	#Message String: No defined keys for this object.
> 	    elsif (($number, $severity, $state)==(0,10,1)) {
> 		return CS_SUCCEED;
> 	    }
> 
> 	#Server message: (In srv_cb)
> 	#Message number: 5701, Severity 10, State 2, Line 1
> 	#Message String: Changed database context to 'master'.
> 	    elsif (($number, $severity, $state)==(5701,10,1) || ($number,
> $severity, $state)==(5701,10,2)) {
> 		return CS_SUCCEED;
> 	    }
> 
> 	#Server message: (In srv_cb)
> 	#Message number: 18085, Severity 16, State 1, Line 83
> 	# Procedure 'sp_helpartition'
> 	#Message String: Object is not partitioned.
> 	    elsif (($number, $severity, $state)==(188085,16,1)) {
> 		return CS_SUCCEED;
> 	    }
> 
> 	    printf STDERR "\nServer message: (In srv_cb)\n";
> 	    printf STDERR "Message number: %ld, Severity %ld, ",
> 	    $number, $severity;
> 	    printf STDERR "State %ld, Line %ld\n", $state, $line;
> 	    
> 	    if (defined($server)) {
> 		printf STDERR "Server '%s'\n", $server;
> 	    }
> 	    
> 	    if (defined($proc)) {
> 		printf STDERR " Procedure '%s'\n", $proc;
> 	    }
> 	    
> 	    printf STDERR "Message String: %s\n", $msg;
> 
> 	    printf STDERR "SQL sent: >%s<\n", $dbh->{SQL}[0];
> 
> 	    CS_SUCCEED;
> 	}
> 
> 	## The pakage
> 	package My::SybLib;
> 
> 	use Sybase::CTlib;
> 
> 	use strict;
> 	use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
> 
> 	require Exporter;
> 	require AutoLoader;
> 
> 	@ISA = qw(Exporter AutoLoader Sybase::CTlib);
> 	@EXPORT = @Sybase::CTlib::EXPORT;
> 	$VERSION = '1.00';
> 
> 	sub new {
> 	    my ($package, $user, $pwd, $server, $app, $attr) = @_;
> 
> 	    # Pre-allocate space for the SQL text in the $dbh struct.
> 	    if ($attr) {
> 	        $attr->{SQL} = '';
> 	    }
> 	    else {
> 	        $attr = {SQL => ''};
> 	    }
> 
> 	###    $package::SUPER->new($user, $pwd, $server, $app, $attr);
> 	    Sybase::CTlib->new($user, $pwd, $server, $app, $attr);
> 	}
> 
> 	sub ct_execute {
> 	    my $dbh = shift;
> 	    my $sql = shift;
> 
> 	    $dbh->{SQL} = $sql;   # Store the $sql in the dbh...
> 
> 	    $dbh::SUPER->ct_execute($sql);  # call the real ct_execute;
> 	}
> 
> 	1;
> 
> Have fun
> 
> F.Pochet
> 
> 
> 
> 
> ----------
> De :
> jrisley@nex-web4.corp.fedex.com[SMTP:jrisley@nex-web4.corp.fedex.com]
> Répondre ŕ : 	jrisley@fedex.com
> Date :	jeudi 24 juin 1999 0:50
> A :	SybPerl Discussion List
> Objet :	Inserting Duplicate Records Message
> 
> All,
> 
> I have the following code where I am trying to insert a record :
> 
> $db=Sybase::CTlib->ct_connect($uid, $pwd, $srv);
> $db->ct_execute($sql);
> if ( $db->ct_results($result) == CS_SUCCEED) {
> 		$row_count = $db->ct_res_info(CS_ROW_COUNT);
> 		if ( $row_count eq 0 ) {
> 			print "No Records where Added with in the
> information you supplied.\n";
> 			print "It is possible that you are trying to insert
> a duplicate
> record.\n"; }
> 		else { print "The PCN was Added to the database.\n"; }
> }
> if ( $db->ct_results($result) == CS_FAIL) {
> 		print "An Error occurred Inserting the data in the
> database.\n";
> 		print "Please Try again. 
\n"; > print "If the problem continues, Please contact the > Webmaster.
\n"; > } > > > In the instance of trying to insert a duplicated record, I get the > following > output: > > index database owner table column > -------------- --------- ------ ------- ---------- > sos_pcn_id_002 svcops dbo sos_pcn pcn_number > No Records where Added with in the information you supplied. > It is possible that you are trying to insert a duplicate record. > > > On the table that I am trying to insert the record, there is an index that > does not allow duplicates of a certain field. Is there a way to trap the > index message so that the first three lines of the above printout do not > appear? > > Thanks for your support! > jason > >