Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
`For-case` wins the lifetime achievement award here, I think

Adbot
ADBOT LOVES YOU

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.
I thought we agreed that it was forever to be known as Duff's Enigma. :mad:

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Lord Uffenham posted:

I thought we agreed that it was forever to be known as Duff's Enigma. :mad:

Who is Duff and what is his enigma?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

MEAT TREAT posted:

Who is Duff and what is his enigma?

http://en.wikipedia.org/wiki/Duff's_device

e: fixed url brokenness

da keebsta knicca
Sep 12, 2000

Oh Ruutu, you are such a card.
I am so thankful I am at my my 2nd to last day here. Here is some sweet "cache" code. We have code that can take a student number and retrieve a bunch of information about that student through an HTTP request.

The best part is that the system only allows for 1 student per HTTP request, if we have a registration form with 700 signups we sometimes need to retrieve 700 students at once with 700 HTTP requests. AWESOME!

To fix this my boss implemented this sweet "cache". It uses a server wide application variable (it is server wide because my boss thinks the whole website should be under 1 Application.cfm file) to store all the students, and then loops through the whole array of up to 1000 students 1 by 1 looking for a student number. It also has some sweet dynamic variable names and some other crap too.

code:
<!--- To improve response time, first check to see if student/prospect profile can be found in array in server memory --->
<cfset found = "no">
<cfif IsNumeric(form.userID) AND Len(form.userID) EQ 8>
	<cfset XMLlist = "studNo,studType,givenName,middleName,surName,birthdate,gender,citizenship,visaType,addr1,addr2,city,province,country,
postalCd,phone,email">
	<cfset nameList = "Student number,Student type,First name,Middle name,Last name,Birthdate,
Gender,Citizenship,Visa type,Address line 1,Address line 2,City,Province,Country,Postal code,Tel,E-mail">
	<cflock scope="APPLICATION" timeout="10" type="READONLY">
	<cfif IsDefined("Application.studentProfile")>
		<cfloop from="1" to="#ArrayLen(Application.studentProfile)#" index="count">
			<cfif Application.studentProfile[count][1] IS form.userID>
				<cfloop from="1" to="#ListLen(XMLlist)#" index="this">
					<cfset thisName = "pr_" & Replace(ListGetAt(XMLlist, this), "-", "", "ALL")>
					<cfset "#thisName#" = Application.studentProfile[count][IncrementValue(this)]>
				</cfloop>
				<cfset found = "yes">
				<cfbreak>
			</cfif>
		</cfloop>
	</cfif>
	</cflock>
I reprogrammed this a year ago to at least use a java collection, but never implemented it because I could never get the other department to give me batch retrieval of student info. IE send a list of 700 student id's and get 700 records back in 1 request.

Also if any of you have never experienced Coldfusion it is best language if you really enjoy typing.

EDIT:

P.S. This code times out if over 100 students are requested, and can sometimes crash the server.

da keebsta knicca fucked around with this message at 21:26 on Nov 26, 2008

ashgromnies
Jun 19, 2004

da keebsta knicca posted:

Also if any of you have never experienced Coldfusion it is best language if you really enjoy typing.

who the gently caress in the history of computing thought, "ah, yes, xml is a decent markup language for organizing data... let's make code out of it"

da keebsta knicca
Sep 12, 2000

Oh Ruutu, you are such a card.

ashgromnies posted:

who the gently caress in the history of computing thought, "ah, yes, xml is a decent markup language for organizing data... let's make code out of it"

PFFT "XML" this language before 6.0 didn't even have an XML parser, lower down in this code it text parses the XML document. The pro's that came up with this thought "ah, yes, HTML is a decent markup language for organizing data... let's make code out of it".

The language was originally created for non programmers, or not good programmers to create basic forms and things that interact with a database. But as soon as you try and do anything of any size it is giant poo poo heap. This was basically my first job out of school, and has super good benefits and good starting pay. Monday I move departments C# ASP.NET 3.5 with full MSDN licenses, and being the only "web dude" will be a dream.

da keebsta knicca fucked around with this message at 21:47 on Nov 26, 2008

Vanadium
Jan 8, 2005

ashgromnies posted:

who the gently caress in the history of computing thought, "ah, yes, xml is a decent markup language for organizing data... let's make code out of it"

It worked for lisp

Zombywuf
Mar 29, 2008

Vanadium posted:

It worked for lisp

Really? Can't say I've seen evidence of this.


Prolog on the other hand...

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Zombywuf posted:

Really? Can't say I've seen evidence of this.


Prolog on the other hand...

:laugh::lol::laugh:

Victor
Jun 18, 2004

ashgromnies posted:

who the gently caress in the history of computing thought, "ah, yes, xml is a decent markup language for organizing data... let's make code out of it"
When compared to some of the other utter and absolute crap out there, like healthcare's 837 file format, XML would be a godsend. One site calls it "overwhelmingly difficult to understand", and yet it's just supposed to be a hierarchical data format. Yes, there is much better for specific cases, but there is also much worse, and at least nubs can use XML...

oldkike
Jan 10, 2003

hey

www.pleasegimmeadollar.com

Zakalwe posted:

A colleague and I were looking through a ray-tracer that someone released as we were implementing one of our own algorithms in it in order to see if the gains we were seeing were peculair to our own code.

We came across a piece of code like this...

code:
for( int axis = 0; axis < 3; axis++){
       switch(axis){
              case 0 : do_stuff(axis); break;
              case 1 : do_stuff(axis); break;
              case 2 : do_stuff(axis); break;
       }
}

:psyduck:

At first glance this kinda looks like Duff's device, but then you realize its just pure utter poo poo.

NotShadowStar
Sep 20, 2000

Victor posted:

When compared to some of the other utter and absolute crap out there, like healthcare's 837 file format, XML would be a godsend. One site calls it "overwhelmingly difficult to understand", and yet it's just supposed to be a hierarchical data format. Yes, there is much better for specific cases, but there is also much worse, and at least nubs can use XML...

He's talking about how XML is pretty good at what it does, but the language syntax of ColdFusion is like XML/HTML because it's what people already know.

So check this out. I work in a highly regarded genetics research lab. I'm the only one who knows anything at all about programming yet genetic research depends highly on it. People who were in my position I think knew very little outside of the classroom.

For example, this is part of a pipeline script written in COMMAND LINE PHP. Let that sink in for a second and then behold
php:
<?
//
// parseField (string, n, delimiter)
//     returns the 'n'th 'delimiter' separated field of 'string'
//     e.g.:  parseField ("how are you?", 3, " \t<br>?") returns 'you'
//     n.b.:  fieldNo starts with one
//

function parseField($inputString, $fieldNo, $fieldDelimiters) {

    //
    // format of tracefile names:
    // lab_murrayId_machinelane_population_family_person.direction_primer_dnaRef
    // murray_13_F09_dani_160_11.g_p1ex3f2r_075.ab1
    // murray_21_H09_phil_20000513_01.b_t3_5uta3f_076.ab1
    //
    $currentField = 0;
    $fieldValue   = "";
    $i = 0;
    $j = 0;

    // allow at most 2 delimiters, default to space if only one specified
    // essentially rendering it as a dummy var

//    if (strlen($fieldDelimiters) == 1) {

//        $fieldDelimiter[1] = " ";
//    }

//    if (strlen($fieldDelimiters) == 0) {
//        $fieldDelimiters[0] = " ";
//        $fieldDelimiters[1] = " ";
//    }

    while ($i < strlen($inputString)) {

        //
        // skip the delimiters
        //

        if  ( (strncmp($inputString[$i], $fieldDelimiters[0], 1) == 0)
          ||  (strncmp($inputString[$i], $fieldDelimiters[1], 1) == 0) ) {

            while ((strncmp($inputString[$i], $fieldDelimiters[0], 1) == 0)
                  || (strncmp($inputString[$i], $fieldDelimiters[1], 1) == 0))  {

                  $i++;

                  if ($i == strlen($inputString)) {
                      break;
                  }
            }
            $fieldValue = "";
        }
        //
        // get current field value
        //
        $currentField++;

        // n.b.  may want to re-write above code to conform to code below so that index is checked in inputSTring before
        // the while loop instead of in it

        if ($i < strlen($inputString)) {

            while ((strncmp($inputString[$i], $fieldDelimiters[0], 1) != 0)
                && (strncmp($inputString[$i], $fieldDelimiters[1], 1) != 0)) {

                $fieldValue = $fieldValue . $inputString[$i];
                $i++;

                if ($i == strlen($inputString)) {
                    break;
                }
            }
        }
        if ($currentField == $fieldNo) {
            //echo "returning: $fieldValue<br>";
            return $fieldValue;
        }

    }
}
?>
I have many, many, many more examples of this type of behavior.

heeen
May 14, 2005

CAT NEVER STOPS

Fenderbender posted:

code:
    $search_code = "sub apply_search_pattern {\n";
    for ( $i = 0 ; $i < $len ; ++$i ) {
        $search_code .= "  \$on[$i] ||= /\\b$query[$i]\\b/io;\n";
    }
    $search_code .= "}\n";

    eval $search_code;
:froggonk:

I think I saw a benchmark somewhere comparing different approaches to sorting, and one was some kind of heap sort using dynamically eval'd strings. It didn't do too bad.

StickGuy
Dec 9, 2000

We are on an expedicion. Find the moon is our mission.

oldkike posted:

At first glance this kinda looks like Duff's device, but then you realize its just pure utter poo poo.
Oh really? Maybe that's why it's already been called Duff's enigma multiple times.

dancavallaro
Sep 10, 2006
My title sucks

NotShadowStar posted:

He's talking about how XML is pretty good at what it does, but the language syntax of ColdFusion is like XML/HTML because it's what people already know.

So check this out. I work in a highly regarded genetics research lab. I'm the only one who knows anything at all about programming yet genetic research depends highly on it. People who were in my position I think knew very little outside of the classroom.

For example, this is part of a pipeline script written in COMMAND LINE PHP. Let that sink in for a second and then behold

quote:

lovely PHP

I have many, many, many more examples of this type of behavior.

Gee, if only there were a built-in function that, say, "exploded" a string into an array based on a delimiter.

Erasmus Darwin
Mar 6, 2001

dancavallaro posted:

Gee, if only there were a built-in function that, say, "exploded" a string into an array based on a delimiter.

I really don't know anything about PHP beyond what I just read on php.net, but it looks like explode only works with a single delimiter (which may have multiple characters). To do multiple delimiters, you apparently need to construct a regex for split or preg_split. You could also do it with strtok and a bit of extra code.

Anyway, I just love how there are so many things wrong with it. I think my favorite is the example invocation:

quote:

// e.g.: parseField ("how are you?", 3, " \t<br>?") returns 'you'

It doesn't work as advertised. It would end up returning "you?" instead of "you" due to the arbitrary delimiter limit of 2.

Even worse, if the code were fixed to support an arbitrary number of delimiters, the example invocation would end up returning "e" since "b" and "r" would become delimiters (as there's no way to designate a multi-character delimiter).

And that's not even getting into the crazy WTFitude of having the second delimiter turn into a space if only a single delimiter is specified.

NotShadowStar
Sep 20, 2000
Indeed, when I started admittedly I wasn't a PHP expert but I looked at that and thought :what:

Why go through all the trouble of making a terrible function that splits strings when we have... split.

Here's another example. A lot of the data crunching depends on the filenames are EXACT or else the whole thing fails and stops processing things (silently, as you'll see); splitting the filename using the werido function listed above. Furthermore, the scientists and research assistants are expected to name the files (up to 384 per experiment) themselves.

You can imagine how this goes.

When something is named wrong there's no explanation as to why so I have to go figure it out and people get angry at me because I'm limping along with this bullshit until I can redo it all.

Here's one of the conditionals on parsing the filename. The filename is expected to start with YYYY-DD-MM_SERIAL#. This little bit checks that.

php:
<?

        if (strncmp($runDir, "200", 3) == 0) {

                $deletePreviousSnp = "delete from snp where run = " . $runId;
                $success           = mysql_query("$deletePreviousSnp");

                //       if (mysql_affected_rows() < 1) {
                //           fputs($errfile, "ERR: " . mysql_error() . "\n");
                //           fputs($errfile, "ERR: delete failed for run: " . $runId . "\n");
                //
                //       } else {
                //           fputs($errfile, "deleted " . mysql_affected_rows() . " from snp "
                //                           . "for run " . $runId . "\n");
                //       }


        } else {

                //
                // cannot update snp records that are from pop-gene-region runs
                //
        }

?>
I think the most frustrating thing about my job is that I work with very intelligent people yet I cannot get through to them that what we have is terrible and I can't keep bandaging.

Captain Cool
Oct 23, 2004

This is a song about messin' with people who've been messin' with you
If you're ever working with a C compiler for microprocessors, and you come across a line like this in the support files
code:
byte portnum;
// get packed data byte
// port number in lower nibble
portnum = getdata(param) << 4 >> 4;
...I'm sorry.

I was 20 and I think I thought I was being clever somewhere else by doing "<<2>>6" to pick off bits 5:4. That one actually might not have been inefficient on some hardware. Still dumb of course.

ZorbaTHut
May 5, 2005

wake me when the world is saved

Ryouga Inverse posted:

When I left today he was "stuck" on a compiler error which said "You can't have a method with the same name as its containing type". How is this a hard error to interpret?

I spend a lot of time in a C++ help channel and, from my experiences there, I've concluded that many people's brains simply freeze up when they see an error message. They see "error" and they just panic and stop thinking.

It used to be that people would come in and ask "what does (incredibly self-explanatory error) mean?" and I'd explain it. But I realized after a while that they didn't need me to explain it. They just need me to repeat it. More than a few times I've quite literally just copy-and-pasted the error message, without the word "error" at the front, and suddenly they understand it, without even realizing what I've done.

I weep for humanity.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ZorbaTHut posted:

I spend a lot of time in a C++ help channel and, from my experiences there, I've concluded that many people's brains simply freeze up when they see an error message. They see "error" and they just panic and stop thinking.

It used to be that people would come in and ask "what does (incredibly self-explanatory error) mean?" and I'd explain it. But I realized after a while that they didn't need me to explain it. They just need me to repeat it. More than a few times I've quite literally just copy-and-pasted the error message, without the word "error" at the front, and suddenly they understand it, without even realizing what I've done.

You know, that makes total sense. Lots of things only click when the context is changed. It seems that taking the information out of the context of "an error message" makes the problem much easier to solve.

quote:

I weep for humanity.

Oh, you were just being a dick. :(

pim01
Oct 22, 2002

pokeyman posted:

You know, that makes total sense. Lots of things only click when the context is changed. It seems that taking the information out of the context of "an error message" makes the problem much easier to solve.

Sure, when dealing with HCI you should always try to avoid causing undue panic. Programmers who shut down on encountering 'Error:', on the other hand, are in the wrong profession.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Really the thing that causes more freeze-ups than anything else in modern C++ is the deluge of a hundred lines (of which three may be informative) that occurs when you gently caress up in a way related to templates.

crazypenguin
Mar 9, 2005
nothing witty here, move along

Otto Skorzeny posted:

Really the thing that causes more freeze-ups than anything else in modern C++ is the deluge of a hundred lines (of which three may be informative) that occurs when you gently caress up in a way related to templates.

Yeah I'm really psyched about Concepts.

da keebsta knicca
Sep 12, 2000

Oh Ruutu, you are such a card.
New job in C#, take over old staffs code.

code:
        //Global variables
        private bool bolColName = true;
        System.Data.Odbc.OdbcDataAdapter obj_oledb_da;
        string strFormat = "CSVDelimited";
        string strCSVFile = "";
        string path ;
        string savePath;
Nothing that crazy except "//Global variables" is the only comment in all of the source code. Thanks.

EDIT:

Looking through their old email on project updates I saw this task was completed. "• Continued reading online .Net book."

Sounds about right.

da keebsta knicca fucked around with this message at 18:02 on Dec 2, 2008

Nippashish
Nov 2, 2005

Let me see you dance!
The last place I worked most of the code was actually pretty good, but we had one programmer who managed to produce some, shall we say, interesting pieces. The only one I can recall well enough to recount was she was given the task of writing a data validator which would sweep over our data as it was read in and make sure all the values were was in the correct ranges and it was all there, etc. The data we were processing came from a team of scientists who were notoriously lazy about data correctness (hence the need for validation in the first place).

Anyway, in a function intended to read a list of numbers from the database and make sure they were all integers between 1 and 10 (despite being stored as doubles) I found something like this:

code:

while (there are more numbers)
{
    x = next_number();

    if (x == 9.99 || x == 7.001 || x == 3.999 || x = 5.01 || x == 2.0011 || x == 1.9999)
    {
       x = round(x);
       // do more stuff
    }
    else if (x == 5.99 || x == 2.99 || x == 8.001 || x == 9.00011 || x == 1.011)
    {
       x = round(x);
       // do the same stuff as the true branch
    }
    else
    {
       // fail to validate
    }
}
The only explanation I was ever able to come up with is that she picked one of the tables we were using (of which hundreds per week were generated), realized that the numbers were slightly perturbed from where they should have been and decided to hard code the particular quirks of that table, only to round the values anyway. :psyduck: (And in two identical branches... I never did figure that one out).

MonkeyMaker
May 22, 2006

What's your poison, sir?
Some code I found in our app at work in a support class for our custom parser (don't ask).

php:
<?
/**
  * function to display template in the product page like finance option in highlights
 * case 3 is added for status page,  if the coupon redeem value is 0 then dont display the couponredeemed msg.
 * else display the redeemed value
  **/
  function EVALTEMPLATE($aarr_args)
  {
    $aarr_args[0] = intval($aarr_args[0]);
        switch ($aarr_args[0]) 
    {
            case 0:
          $lstr_rtn_value = $aarr_args[1];
                  break;
      case 1:
          $lstr_rtn_value = $aarr_args[2];
                  break;
      case 2:
          if (isset($aarr_args[3]) && $aarr_args[0] != "")
          {
            $lstr_rtn_value = $aarr_args[1];
              }
          else
          {
                  $lstr_rtn_value = $aarr_args[2];
          }
        break;
            case 3:
                    if (isset($aarr_args[1]) && $aarr_args[1] > "0")
          {
            $lstr_rtn_value = $aarr_args[2];
              }
                    else
                    {
                        $lstr_rtn_value = '';
                    }
        break;
      default:
          $lstr_rtn_value = '';
    }
    return $lstr_rtn_value;
    }
?>
This is used many, many, many times.

geetee
Feb 2, 2004

>;[

da keebsta knicca posted:

Looking through their old email on project updates I saw this task was completed. "• Continued reading online .Net book."

Sounds about right.

Come on :( You can't knock a guy for trying to learn.

da keebsta knicca
Sep 12, 2000

Oh Ruutu, you are such a card.

geetee posted:

Come on :( You can't knock a guy for trying to learn.

No I can't I haven't coded C# ASP.NET myself for a couple of years and have to reference a lot lately. But I just found it I guess ironic after going through the app.

Murodese
Mar 6, 2007

Think you've got what it takes?
We're looking for fine Men & Women to help Protect the Australian Way of Life.

Become part of the Legend. Defence Jobs.
Code from a coworker I noticed in a library that's meant to combine CSS or JS files into a single file, minimize them and cache them (ie. only 2 http requests needed)

php:
<?
//<snip $content = file_get_contents() the css file>                
    if(isset($content))
    {
        $content = $this->_fix_urls($group, $content, $style['view']);
        
        if($this->csstidy_on)
        {
            $this->csstidy->load_template($this->csstidy_compress);
            // SLOW AS gently caress
            $this->csstidy->parse($content);
            $document .=  $this->csstidy->print->plain();
        }
        else
        {
            $document .=  $content;
        }
    }

    if($this->_needs_rewrite($document, $filename))
    {
            $this->_write_file($document, $filename);
    }
?>
Yes, he ran the slow as poo poo function every single pageload and all the caching did was decide whether to write the file again or not :sigh:

Execution time has now dropped from ~8.65s to 0.03s after some tlc

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
More from the saga of terrible sdet!

I told him to make sure to separate view and controller/model code, and this is what he's come up with:

code:
        private void groupBoxRecordFormat_Enter(object sender, EventArgs e)
        {
            PrepareWriteRecordFormat();
        }

        private void PrepareWriteRecordFormat()
        {
            if (radioButtonHigh.Checked)
            {
                _RecordFormat = "2";
            }
            else if (radioButtonMedium.Checked)
            {
                _RecordFormat = "3";
            }
            else if (radioButtonLow.Checked)
            {
                _RecordFormat = "4";
            }
        }
:ughh:

Oh, also:

code:
        private void ProcessRecordButton()
        {
            if (_recordButtonIsOn)
            {
                _recordButtonIsOn = false;  // Button is dis-Engaged
            }
            else
            {
                _recordButtonIsOn = true;  // Button is Engaged
            }
        }

Potassium Problems
Sep 28, 2001
code:
--------------------------------------------------------------------------
--Notes:Everytime u run this it will give u a new id so it can be used anywhere to
--get a unique ID for you Inserts,....
--Changes on:  Change Flag:
---------------------------------------------------------------------------------
ALTER  PROCEDURE [dbo].[spSelect_NextID]
as

SET NOCOUNT ON
 
begin 
 select NextID from dbo.tblNextID
 
 update dbo.tblNextID
 set NextID = NextID + 1 
end 
Return
Auto increment? @@IDENTITY? gently caress outta here with those, we got a key generating table :cool:

Victor
Jun 18, 2004
Not to mention reentrancy issues...

Potassium Problems
Sep 28, 2001
I think I'm going to make note of the current value of the table, reset it to 1, and watch the excitement unfold.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Lone_Strider posted:

I think I'm going to make note of the current value of the table, reset it to 1, and watch the excitement unfold.

"What's this bullshit table full of sequential numbers? We don't need this!"
code:
DROP TABLE tblNextID

TRUNCATE TABLE tblNextID
I can't decide which would be the best!

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

royallthefourth posted:

"What's this bullshit table full of sequential numbers? We don't need this!"
code:
DROP TABLE tblNextID

TRUNCATE TABLE tblNextID
I can't decide which would be the best!

I like TRUNCATE best because it isn't immediately obvious what's going on when the app breaks. Also, potentially it could go for a while without being noticed (if previous records are deleted)

Zombywuf
Mar 29, 2008

Lone_Strider posted:

code:
--------------------------------------------------------------------------
--Notes:Everytime u run this it will give u a new id so it can be used anywhere to
--get a unique ID for you Inserts,....
--Changes on:  Change Flag:
---------------------------------------------------------------------------------
ALTER  PROCEDURE [dbo].[spSelect_NextID]
as

SET NOCOUNT ON
 
begin 
 select NextID from dbo.tblNextID
 
 update dbo.tblNextID
 set NextID = NextID + 1 
end 
Return
Auto increment? @@IDENTITY? gently caress outta here with those, we got a key generating table :cool:

Be very careful here, there are legitimate reasons to do this. Although unless your db's default isolation level is serializable (and you db properly supports serializable (which it doesn't)) this is the wrong code to do it. There are two reasons to do this: the first is where keys must be unique across multiple tables (i.e. table1.key must never be equal to table2.key), the second is if you require sequential keys. If a transaction that has allocated a key for an identity column rolls back when there is another transaction active that has allocated the key after it, the rolled back transaction will leave a gap in the keys.

Of course if your system doesn't need either of these there is no reason for this function to exist and as I said, it's wrong.

The fix would be to set the isolation level to at least repeatable read and use an update lock table hint on tblNextID in the SELECT statement.

Potassium Problems
Sep 28, 2001
It's SQL 2005, keys have no need to be unique to multiple tables, nor do the keys have to be sequential. The dev who created this is one of those "stuck in his ways" people who's best fit is maintaining some Access 97 application. I have the joy of rewriting everything he's done!

I actually ran the truncate just to see what would break and where, but I haven't heard a thing & the "counter" is still at 1. I hope this is just an old procedure that no one uses anymore.

spiritual bypass
Feb 19, 2008

Grimey Drawer

Lone_Strider posted:

I actually ran the truncate

That's some serious balls you got there. What made you think it wouldn't be an absolute disaster?

Adbot
ADBOT LOVES YOU

Potassium Problems
Sep 28, 2001
small company, backed up the table beforehand & it wasn't part of a database that was mission critical.

But I'm gonna restore it regardless before someone who works here sees my post & I wind up explaining myself

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply