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
Biodome
Nov 21, 2006

Gerry
Not sure if this is the right place for this but I'm taking a database organization class and I'm doing a lab focusing on SQL Triggers. I haven't had an issue with the SQL until now, I just can't seem to grasp the trigger stuff. We have to create a trigger that will update a field in a column on one table whenever an insert, update, or delete event is done on another table.

We're using SQL Server 2014 and I know the syntax for triggers but I just can't come up with the correct way to do this. Anyone have any resources with more information or explanations for trigger that will help me better understand them? Maybe it's the way my textbook is explaining them.

Thank you.

Adbot
ADBOT LOVES YOU

nielsm
Jun 1, 2009



Uh, something like this maybe?

CREATE TRIGGER footrigger ON footable
AFTER INSERT, UPDATE, DELETE
AS UPDATE loggingtable SET lastactiontime=NOW WHERE tablename='footable';

And if you need to look at what data was actually modified there are two pseudo-tables called "inserted" and "deleted" you can reference in the trigger action.

Biodome
Nov 21, 2006

Gerry

nielsm posted:

Uh, something like this maybe?

CREATE TRIGGER footrigger ON footable
AFTER INSERT, UPDATE, DELETE
AS UPDATE loggingtable SET lastactiontime=NOW WHERE tablename='footable';

And if you need to look at what data was actually modified there are two pseudo-tables called "inserted" and "deleted" you can reference in the trigger action.

Thank you for this. I understand how your trigger example works but the one I need to create is going to need those insert and deleted pseudo-tables, I think.

I could do something that would auto increment the number in that field but it would give a wrong answer if someone did something besides just Inserting.

To give more information so my question makes sense, I basically need to update a field with the number of times a movie has been rented. That column is in its own table called Movies with the columns movie_id, and num_rentals. That table needs to be updated anytime a new record is inserted, deleted, or updated into a table called customer_rentals with the matching movie_id.

For instance, if customer A rents ironman, which has a movie_id of 2, this will add a new record to customer_rentals with all his info and the movie he rented, and then my trigger should update the num_rentals field in the movies table to add another rental count for the movie_id =2.

It actually helped me understand a bit better when I wrote it out like that, it's just coming up with the actual commands that's the hard part, haha. I guess that's the point. I just can't think of the commands needed to see what the previous num_rental was and to add one to it. I bet it's starting me right in the face.

nielsm
Jun 1, 2009



Biodome posted:

Thank you for this. I understand how your trigger example works but the one I need to create is going to need those insert and deleted pseudo-tables, I think.

I could do something that would auto increment the number in that field but it would give a wrong answer if someone did something besides just Inserting.

To give more information so my question makes sense, I basically need to update a field with the number of times a movie has been rented. That column is in its own table called Movies with the columns movie_id, and num_rentals. That table needs to be updated anytime a new record is inserted, deleted, or updated into a table called customer_rentals with the matching movie_id.

For instance, if customer A rents ironman, which has a movie_id of 2, this will add a new record to customer_rentals with all his info and the movie he rented, and then my trigger should update the num_rentals field in the movies table to add another rental count for the movie_id =2.

It actually helped me understand a bit better when I wrote it out like that, it's just coming up with the actual commands that's the hard part, haha. I guess that's the point. I just can't think of the commands needed to see what the previous num_rental was and to add one to it. I bet it's starting me right in the face.

Why do you need to know the exact old or new rental count, when the SQL server can know them for you?

How would you modify the rental count if it wasn't in a trigger, but just as a standalone operation?

Now do the same but based on number of occurrences of a movie in the "inserted" and "deleted" pseudo-tables.

Peristalsis
Apr 5, 2004
Move along.
Between the following three methods for setting the change event method on an HTML element, is one preferred over the others?
1) Set the onchange attribute in the HTML (<some_element>id="an_element" onchange="some_function()">...</some_element>
2) Use JQuery's change method ($("some_selector").change(some_function)
3) Use JQuery's on method ($("some_selector").on("change", some_function)

A coworker seems to think method 1 is non-standard, and is unsure that it will be supported by all browsers (seems to work fine in the two I have installed, but I thought I'd ask).

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Peristalsis posted:

Between the following three methods for setting the change event method on an HTML element, is one preferred over the others?
1) Set the onchange attribute in the HTML (<some_element>id="an_element" onchange="some_function()">...</some_element>
2) Use JQuery's change method ($("some_selector").change(some_function)
3) Use JQuery's on method ($("some_selector").on("change", some_function)

A coworker seems to think method 1 is non-standard, and is unsure that it will be supported by all browsers (seems to work fine in the two I have installed, but I thought I'd ask).

onchange should be fine for new browsers. Might have issues with older versions of IE.

nielsm
Jun 1, 2009



Have you already bought in to JQuery? If so, use the "on" method.

If not, consider using standard DOM: document.getElementById("an_element").addEventHandler("change", function(e) { ...} )
(ad far as I remember)

Your first method is definitely obsolete.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

nielsm posted:

Have you already bought in to JQuery? If so, use the "on" method.

If not, consider using standard DOM: document.getElementById("an_element").addEventHandler("change", function(e) { ...} )
(ad far as I remember)

Your first method is definitely obsolete.

It is most certainly not obsolete

https://developer.mozilla.org/en-US/docs/Web/Events/change

SurgicalOntologist
Jun 17, 2004

I'm designing a system to store time series data. I have some experience with SQL (and plenty of experience with in-memory analysis of time series loaded from CSVs) and figured SQL was the way to go, but I just learned of the existence of specialized time series databases and array databases. Most of the discussion I can find focuses on how well they scale, which isn't really an issue for us. We'll never have that many transactions. What else should I consider to choose one of these solutions over the others?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Peristalsis posted:

Between the following three methods for setting the change event method on an HTML element, is one preferred over the others?
1) Set the onchange attribute in the HTML (<some_element>id="an_element" onchange="some_function()">...</some_element>
2) Use JQuery's change method ($("some_selector").change(some_function)
3) Use JQuery's on method ($("some_selector").on("change", some_function)

A coworker seems to think method 1 is non-standard, and is unsure that it will be supported by all browsers (seems to work fine in the two I have installed, but I thought I'd ask).

2 is implemented trivially using 3, so you're really down to two choices, if that helps.

Peristalsis
Apr 5, 2004
Move along.
I appreciate the responses. It sounds like what I figured - the JQuery methods are sort of the de facto standard (or at least more common), but plenty of people still use HTML attributes.

nielsm posted:

Have you already bought in to JQuery? If so, use the "on" method.

If not, consider using standard DOM: document.getElementById("an_element").addEventHandler("change", function(e) { ...} )
(ad far as I remember)

Why's this? I thought all the cool kids were still using JQuery.

But yes, our code has plenty of JQuery in it, and probably no direct DOM calls.

nielsm posted:

Your first method is definitely obsolete.

I'll probably replace the HTML attributes with JQuery calls tomorrow. No sense in using the less-preferred approach, especially since my coworker seems unfamiliar with it. The original code I had used the change method, but for some reason it stopped working at some point. I didn't even notice the change calls were there when I put in the HTML attributes the other day, to fix the problem. If I had, I probably would have tried to fix them, instead. I'm still a novice at JavaScript, so it still seems very temperamental and hard to debug to me.

Thanks again for your input(s).

Sedro
Dec 31, 2008
People are moving away from JQuery.

It''s mainly a compatibility shim for older browsers, which is not so relevant any more as the everyone drops support for IE6/7/8. Also modern tools like react offer much better solutions to DOM manipulation.

There are some anti-jquery movements even:
http://vanilla-js.com/
http://youmightnotneedjquery.com/

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Peristalsis posted:

I appreciate the responses. It sounds like what I figured - the JQuery methods are sort of the de facto standard (or at least more common), but plenty of people still use HTML attributes.


Why's this? I thought all the cool kids were still using JQuery.

But yes, our code has plenty of JQuery in it, and probably no direct DOM calls.


I'll probably replace the HTML attributes with JQuery calls tomorrow. No sense in using the less-preferred approach, especially since my coworker seems unfamiliar with it. The original code I had used the change method, but for some reason it stopped working at some point. I didn't even notice the change calls were there when I put in the HTML attributes the other day, to fix the problem. If I had, I probably would have tried to fix them, instead. I'm still a novice at JavaScript, so it still seems very temperamental and hard to debug to me.

Thanks again for your input(s).

All JQuery is doing is setting the exact HTML attributes you are talking about. Unless you are already using JQuery everywhere else, I don't see a reason to start now just because.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Sedro posted:

People are moving away from JQuery.

It''s mainly a compatibility shim for older browsers, which is not so relevant any more as the everyone drops support for IE6/7/8. Also modern tools like react offer much better solutions to DOM manipulation.

There are some anti-jquery movements even:
http://vanilla-js.com/
http://youmightnotneedjquery.com/

Also, the JQuery event handling library is bullshit.
a) Whenever a jquery event fires, it normalizes it (as back in the old days, properties for events were not common between browsers, so jquery tries to make the properties consistent.) The code that does this is slow as gently caress.
b) JQuery has to track the event handlers in its own internal event handler cache - so an event fires, it's raised in JQuery object itself rather than execution context where the event was defined. This is infuriating to read in the memory profiler, and also has other consequences - like, in vanilla js, if you define an event handler on a div, and remove the div, it goes away, but in JQuery, the event handler lives on in the event handler cache.
c) The only thing that you can't easily do in vanilla JS that you can do in JQuery is event delegation (e.g. bind an event to fire on a selector.) However, just adding the event to whatever element you would want is actually a problem because vanilla JS event handling isn't garbage slow.

Peristalsis
Apr 5, 2004
Move along.

Sedro posted:

People are moving away from JQuery.

It''s mainly a compatibility shim for older browsers, which is not so relevant any more as the everyone drops support for IE6/7/8.

Oh, I thought its main point was that you could do things with 1/10th as much typing as with DOM commands. (That's not intended to be sarcastic, I just really didn't realize this was a point of it.)

Sedro posted:

Also modern tools like react offer much better solutions to DOM manipulation.

Cool, I'll add this to my list of stuff I want to read about.

Sedro posted:

There are some anti-jquery movements even:
http://vanilla-js.com/
http://youmightnotneedjquery.com/

I guess the one saving grace about being behind the times in this field is that if you get far enough behind, you look edgy and forward thinking. "JQuery? Nah, I never learned that, I was waiting for a real solution, you know?" (Puffs condescendingly on home-rolled cigarette made with locally sourced, free-range, dolphin-safe tobacco.)

Skandranon posted:

All JQuery is doing is setting the exact HTML attributes you are talking about. Unless you are already using JQuery everywhere else, I don't see a reason to start now just because.

Well, right, I knew it was just a library lying over JavaScript doing basic JavaScript/DOM stuff underneath, but I do want to stick with common idioms and best practices. And yeah, there's a good bit of JQuery already in the code. So much so that calling the DOM objects directly would look weird and out of place.

Bruegels Fuckbooks posted:

Also, the JQuery event handling library is bullshit.
a) Whenever a jquery event fires, it normalizes it (as back in the old days, properties for events were not common between browsers, so jquery tries to make the properties consistent.) The code that does this is slow as gently caress.
b) JQuery has to track the event handlers in its own internal event handler cache - so an event fires, it's raised in JQuery object itself rather than execution context where the event was defined. This is infuriating to read in the memory profiler, and also has other consequences - like, in vanilla js, if you define an event handler on a div, and remove the div, it goes away, but in JQuery, the event handler lives on in the event handler cache.
c) The only thing that you can't easily do in vanilla JS that you can do in JQuery is event delegation (e.g. bind an event to fire on a selector.) However, just adding the event to whatever element you would want is actually a problem because vanilla JS event handling isn't garbage slow.

That's interesting to know, thanks.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I'd consider the onwhatever attributes in the markup a smell because you're mashing your logic into your display/view and it doesn't belong there.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Bruegels Fuckbooks posted:

c) The only thing that you can't easily do in vanilla JS that you can do in JQuery is event delegation (e.g. bind an event to fire on a selector.) However, just adding the event to whatever element you would want is actually a problem because vanilla JS event handling isn't garbage slow.

there is a magic way to do this using the onanimationstart hack. i kind of just wish it was native web functionality.

everythingWasBees
Jan 9, 2013




Any recommended resources for learning Lua? I'm coming from a C++ background, if that changes anything.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
I always look at JavaScript as a net you lay over already functioning HTML & CSS. That's why on attributes are a smell. You already conceding defeat that your site will suck poo poo for the first 5-10 seconds on mobile, or not work at all without JavaScript.

If you treat it as a net laid over the top to boost the functionality to the optimal experience, odds are your site will feel like it loads faster, and will possibly have less bugs due to the stable foundation.

JQuery is sometimes nice for that (compatibility is a given when working with it because it's so heavily used) but I would like to leave it behind soon enough. I write all libraries as jquery free anyway, and much of the standard DOM library is nicer to work with due to actually throwing errors on empy selectors (one of the biggest stumbling blocks in beginner jquery ini, and one that trips up the beast of us)

Hughlander
May 11, 2005

everythingWasBees posted:

Any recommended resources for learning Lua? I'm coming from a C++ background, if that changes anything.

Programming in Lua (book) and reading some WoW addons was how I did it. There's intentionally not much to the language but if you haven't done any functional programming that's about the only part that will trip you. Currying, generators, etc... Are frequently used in production Lua.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Maluco Marinero posted:

I always look at JavaScript as a net you lay over already functioning HTML & CSS. That's why on attributes are a smell. You already conceding defeat that your site will suck poo poo for the first 5-10 seconds on mobile, or not work at all without JavaScript.

If you treat it as a net laid over the top to boost the functionality to the optimal experience, odds are your site will feel like it loads faster, and will possibly have less bugs due to the stable foundation.

JQuery is sometimes nice for that (compatibility is a given when working with it because it's so heavily used) but I would like to leave it behind soon enough. I write all libraries as jquery free anyway, and much of the standard DOM library is nicer to work with due to actually throwing errors on empy selectors (one of the biggest stumbling blocks in beginner jquery ini, and one that trips up the beast of us)

What are you talking about? The sites that fail without JavaScript don't suffer from excessive use of onchange, they suffer from only sending down an empty <div id=content>. I mean, if you're using smelly on-attributes then you at least have to provide some markup to contain them.

ToxicFrog
Apr 26, 2008


everythingWasBees posted:

Any recommended resources for learning Lua? I'm coming from a C++ background, if that changes anything.

First, make sure you're looking at the docs for the right version. Lua 5.0/5.1/5.2/5.3 and LuaJIT are mostly compatible, but the differences between, say, 5.0 and 5.2 are a lot greater than between any two minor python versions, for example. (LuaJIT is mostly Lua 5.1 but with some 5.2 and 5.3 features.)

With that out of the way, the Lua reference manual is actually a pretty quick read; it's not a large language. Chapters 1-3 cover the language itself; from there, you can read 4 and 5 (the liblua C API) if you're going to be working on a Lua<->C/++ interface, or skip straight to 6 (the lua standard libraries) if you're going to be working in pure lua. That said, if you're mostly used to C++ you may run into some surprises.

If you want a gentler introduction that doesn't assume you already have at least some familiarity with (e.g.) coroutines and closures, Programming in Lua is the go-to book; the first edition (Lua 5.0) is available online, and the second and third editions are available for purchase.

There's also a community-maintained wiki (although how up to date it is can be wildly variable), and a #lua channel on Freenode that is sometimes helpful.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

pokeyman posted:

What are you talking about? The sites that fail without JavaScript don't suffer from excessive use of onchange, they suffer from only sending down an empty <div id=content>. I mean, if you're using smelly on-attributes then you at least have to provide some markup to contain them.

I mean that it's a smell that your HTML and JavaScript are not decoupled as well as they should be. I guess it's true that you need some sort of content to even get to using on handlers, but then the empty <div id=content> is more a caricature (one I'm well aware still exists for non app sites, but it's still a caricature), sites overly dependant on JavaScript are more often on a spectrum than being 100% one way or the other.

Vegetable
Oct 22, 2010

I'm taking an SQL class and designing a very rudimentary database in Microsoft Access.

So I have Table A with a list of employees (one of the attributes is "Employee Type"). I also have Table B meant to display the list of cashiers. How do I make it such that all employees with Employee Type "Cashier" will show up in the Cashier table?

baquerd
Jul 2, 2007

by FactsAreUseless

Vegetable posted:

I'm taking an SQL class and designing a very rudimentary database in Microsoft Access.

So I have Table A with a list of employees (one of the attributes is "Employee Type"). I also have Table B meant to display the list of cashiers. How do I make it such that all employees with Employee Type "Cashier" will show up in the Cashier table?

Something along the lines of this, if I'm understanding you correctly:

select * into <cashiers table> from <employees table> where employee_type = "Cashier"

nielsm
Jun 1, 2009



Vegetable posted:

I'm taking an SQL class and designing a very rudimentary database in Microsoft Access.

So I have Table A with a list of employees (one of the attributes is "Employee Type"). I also have Table B meant to display the list of cashiers. How do I make it such that all employees with Employee Type "Cashier" will show up in the Cashier table?

The question is if they want you to copy the data into table B, or they want you to make a View.

In Access, what SQL calls a View is called a (saved and named) query, but it is a proper view and you can use it as a relation to select data from in further queries.

raminasi
Jan 25, 2005

a last drink with no ice
There's an SQL thread if you really feel like getting into the weeds.

Gul Banana
Nov 28, 2003

Maluco Marinero posted:

I mean that it's a smell that your HTML and JavaScript are not decoupled as well as they should be. I guess it's true that you need some sort of content to even get to using on handlers, but then the empty <div id=content> is more a caricature (one I'm well aware still exists for non app sites, but it's still a caricature), sites overly dependant on JavaScript are more often on a spectrum than being 100% one way or the other.

Is there a better method than div#content to produce a starting point for JS to render into?

nielsm
Jun 1, 2009



Gul Banana posted:

Is there a better method than div#content to produce a starting point for JS to render into?

Well you could deliver the content inline during initial page load, instead of depending on a script to load it afterwards.

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
The thing is these days you can and lots of people do use React, which if you build right is capable of server side and client side render. But then you're righting absolutely everything in presentation in JavaScript then to reap the dividends. For my business this is what we do, we use node/JavaScript as a templating later and send JSON to it from our 'proper' backend (usually Python Django for the scale of projects we do)

That said, most of our sites take the enhancement approach of JavaScript so they load quick and then just apply little touches of JavaScript to improve the experience. The type where you render on the client is reserved for more complex applications, but it doesn't have to be the whole site, stuff like this is contained to the interactive portion:

https://archierose.com.au/tailored-spirits/whisky#content

Sorry for the email gate on that one, not a fan but it's what the client wanted.

Obviously this prevents people with JavaScript disabled from interacting with the site, but that's a trade off the client accepts, and generally we'll do the best we can to make for a 'reasonable' experience for people with JavaScript turned off while acknowledging that it is likely over engineering to try and make more complex stuff JavaScript free.

Lpzie
Nov 20, 2006

nvm.

Hadlock
Nov 9, 2004

For those of you using JIRA and/or Bamboo by Atlassian as part of continuous integration,

What kind of test case manager are you using?

It looks like Zephyr is the 800lb gorilla, followed distantly by X-ray and Zapi. Is anyone using these? What do you use, what do you hate about it?

baquerd
Jul 2, 2007

by FactsAreUseless

Hadlock posted:

For those of you using JIRA and/or Bamboo by Atlassian as part of continuous integration,

What kind of test case manager are you using?

It looks like Zephyr is the 800lb gorilla, followed distantly by X-ray and Zapi. Is anyone using these? What do you use, what do you hate about it?

ZAPI is just some Zephyr API hooks. It's pretty cool, we use it to make annotation based linkages to our acceptance tests which are recorded as Zephyr test executions in JIRA. So all we do is basically @ZTest(Story=MYPROJ-121,AC=1) and everything else is handled for us so anyone with access to JIRA can see test execution results run from Jenkins.

program666
Aug 22, 2013

A giant carnivorous dinosaur
I want to avoid using resharper, a huge plugin for visual studio, since the only feature I would use would probably be the stuff that analyses performance (called "profiling" I think), so I was wondering if there is another lighter tool that I could use instead. I mostly use vim and bash to program so I profoundly dislike when visual studio is slow when I have to use it.

raminasi
Jan 25, 2005

a last drink with no ice

program666 posted:

I want to avoid using resharper, a huge plugin for visual studio, since the only feature I would use would probably be the stuff that analyses performance (called "profiling" I think), so I was wondering if there is another lighter tool that I could use instead. I mostly use vim and bash to program so I profoundly dislike when visual studio is slow when I have to use it.

VS2015 has basic profiling capabilities built in.

program666
Aug 22, 2013

A giant carnivorous dinosaur
thanks man

Hughlander
May 11, 2005

While you have your answer to me the real reason to use resharper is over powered refactoring tools. Do boot it up if you need to remove classes or break subsystems up logically. Note however at work I'm accused of being a JetBrains Schill complete with a count of how many times I try to get people to drink the tasty tasty koolaid

program666
Aug 22, 2013

A giant carnivorous dinosaur
Does resharper have some other better profiling tool? Or is it about as good as visual studio's? I didn't want to make visual studio freeze even more, that thing when I click on the text and the whole window just freezes is kind of maddening.

raminasi
Jan 25, 2005

a last drink with no ice

program666 posted:

Does resharper have some other better profiling tool? Or is it about as good as visual studio's? I didn't want to make visual studio freeze even more, that thing when I click on the text and the whole window just freezes is kind of maddening.

For the record, this is definitely abnormal behavior.

Adbot
ADBOT LOVES YOU

program666
Aug 22, 2013

A giant carnivorous dinosaur
Many things freezes, I think this happen during some windows update process because it's a HDD so anything related to the filesystem have all these hicups, but it affects vs the worst But this is a work laptop filled with programs from my company so God knows what exactly makes vs unusable at least once a week, but avoiding making everything even slower seems like a good idea

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