As was foretold, we've added advertisements to the forums! If you have questions, or if you encounter any bugs, please visit this thread: https://forums.penny-arcade.com/discussion/240191/forum-advertisement-faq-and-reports-thread/

SELECT * FROM posts WHERE tid = 'PA PROGRAMMING THREAD'

16465676970100

Posts

  • bowenbowen How you doin'? Registered User regular
    Highball question, anyone familiar with querying and processing results with CDatabase back in MFC? I can't really recall, I apparently am using CDatabase properly (I can connect just fine) but I can't figure out how to pass a query and process the results.

    I'm assuming it uses CRecordset ? But how?

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    rs.Open(CRecordset::dynaset,query);
    

    Is as much as I've turned up with the MSDN, but how does one process the query?

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • urahonkyurahonky Registered User regular
    I don't know if you guys listen to music while you program, but I do. And this song came on my Pandora radio station and had to share.

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    Daft Punk is great coding music.

  • bowenbowen How you doin'? Registered User regular
    Mozart and Bach all up ins.

    I'm classy motherfuckers.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • urahonkyurahonky Registered User regular
    bowen wrote: »
    Mozart and Bach all up ins.

    I'm classy motherfuckers.

    I have it set to shuffle all which includes my classical station. Just great to have a variety of music to code to.

  • IncindiumIncindium Registered User regular
    edited April 2012
    bowen wrote: »
    rs.Open(CRecordset::dynaset,query);
    

    Is as much as I've turned up with the MSDN, but how does one process the query?


    You need to derive a custom class from CRecordset from what I remember doing... Here is something from some legacy code I pulled up...

    from the .h file
    
    class CPCustomRS : public CRecordset
    {
    public:
    
    	CPCustomRS(CDatabase& DB);
    
    	long    m_RID;
    	CString m_CODE;
    	CString m_NAME;
    	CString m_ATTENTION;
    	CString m_ADDRESS1;
    	CString m_ADDRESS2;
    	CString m_CITY;
    	CString m_REGION;
    	CString m_POSTALCODE;
    	CString m_COUNTRY;
    	BYTE    m_STAT_RID;
    	CString m_NOTES;
    
    	virtual CString GetDefaultSQL();
    	virtual void DoFieldExchange(CFieldExchange* pFX);
    };
    
    

    from .cpp file
    CPCustomRS::CPCustomRS (CDatabase& DB)
      : CRecordset(DB)
    {
    	m_RID        = 0;
    	m_CODE       = _T("");
    	m_NAME       = _T("");
    	m_ATTENTION  = _T("");
    	m_ADDRESS1   = _T("");
    	m_ADDRESS2   = _T("");
    	m_CITY       = _T("");
    	m_REGION     = _T("");
    	m_POSTALCODE = _T("");
    	m_COUNTRY    = _T("");
    	m_STAT_RID    = 0;
    	m_NOTES       = _T("");
    	
    	m_nFields      = 12;
    	m_nDefaultType = dynaset;
    }
    
    
    CString CPDistributorRS::GetDefaultSQL()
    {
    	return _T("[dbo].[V_CUSTOM_RW]");
    }
    
    
    void CPDistributorRS::DoFieldExchange(CFieldExchange* pFX)
    {
    	pFX->SetFieldType(CFieldExchange::outputColumn);
    	
    	RFX_Long(pFX, _T("[RID]"), m_RID);
    	RFX_Text(pFX, _T("[code]"), m_CODE);
    	RFX_Text(pFX, _T("[NAME]"), m_NAME);
    	RFX_Text(pFX, _T("[ATTENTION]"), m_ATTENTION);
    	RFX_Text(pFX, _T("[ADDRESS1]"), m_ADDRESS1);
    	RFX_Text(pFX, _T("[ADDRESS2]"), m_ADDRESS2);
    	RFX_Text(pFX, _T("[CITY]"), m_CITY);
    	RFX_Text(pFX, _T("[REGION]"), m_REGION);
    	RFX_Text(pFX, _T("[POSTALCODE]"), m_POSTALCODE);
    	RFX_Text(pFX, _T("[COUNTRY]"), m_COUNTRY);
    	RFX_Byte(pFX, _T("[STAT_RID]"), m_STAT_RID);
    	RFX_Text(pFX, _T("[NOTES]"), m_NOTES);
    }
    


    From where you'd actually use it in code.
    CPCustomRS rsCustom (pMyApp->m_Database);
    	if (rsCustom.Open (CRecordset::forwardOnly,NULL,CRecordset::readOnly|CRecordset::executeDirect)){
    		while (!rsCustom.IsEOF()){
    			if (!rsCustom.IsDeleted()){
                                
                               CString temp = rsCustom.m_ADDRESS1;
    			}
    			rsCustom.MoveNext();
    		}
    		rsCustom.Close ();
    	}
    

    Incindium on
    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    My coding music varies from American hard rock like Chevelle, 10 Years and Breaking Benjamin, to heavy metal like Killswitch Engage, Pantera and Atreyu, to softer alt rock like Coldplay and Young the Giant, to darker, harder electronic stuff like dub step, drum and bass and electro house.

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • urahonkyurahonky Registered User regular
    GnomeTank wrote: »
    My coding music varies from American hard rock like Chevelle, 10 Years and Breaking Benjamin, to heavy metal like Killswitch Engage, Pantera and Atreyu, to softer alt rock like Coldplay and Young the Giant, to darker, harder electronic stuff like dub step, drum and bass and electro house.

    There's a 90's hip hop station that I've started listening to that is pretty awesome to program to. I tried Smooth Jazz, but it was TOO relaxing. I need something to keep me going.

  • urahonkyurahonky Registered User regular
    Just got wind that I'll be shifting over to another project. Sounds like we don't think we'll be getting any more money out of my current project to keep 3 people working on it until September.

  • iTunesIsEviliTunesIsEvil Cornfield? Cornfield.Registered User regular
    "Wellllllllp, looks like this unwieldly, out-of-hand project's going down the crapper! Thanks for your hard work, honky. Now, on to this completely different project where that TOTALLY will NOT happen this time. Promise. Scout's honor."

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    At least that's the best way for a "we don't have enough money..." situation to go.

  • bowenbowen How you doin'? Registered User regular
    edited April 2012
    Incindium wrote: »
    bowen wrote: »
    rs.Open(CRecordset::dynaset,query);
    

    Is as much as I've turned up with the MSDN, but how does one process the query?


    You need to derive a custom class from CRecordset from what I remember doing... Here is something from some legacy code I pulled up...

    Thanks @Incidndium I actually got it before I checked back here. Here's what I did:
    CDatabase db;
    LPCTSTR connectionString = _T("... My database stuff here...");
    db.OpenEx(connectionString, CDatabase::openReadOnly | CDatabase::noOdbcDialog);
    
    wchar_t query[256];
    swprintf(query,L"SELECT dnStr FROM personnel WHERE emp_user ='%s'",user);
    
    CRecordset rs(&db);
    rs.Open(CRecordset::forwardOnly,query);
    CDBVariant varValue;
    
    if(!rs.IsEOF())
    {
        rs.GetFieldValue((short)0,varValue);
    }
    
    MultiByteToWideChar(CP_ACP,0,*varValue.m_pstringA,strlen(*varValue.m_pstringA),userDN,sizeof(userDN));
    
    rs.Close();
    db.Close();
    

    Also, yes, I live dangerously.

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    Count your blessings honky, count them.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • IncindiumIncindium Registered User regular
    LPCTSTRs and wchar_ts and CDBVariants, Oh My!

    Ha... I'm glad I don't actively work with C++/MFC anymore.

    steam_sig.png
    Nintendo ID: Incindium
    PSN: IncindiumX
  • bowenbowen How you doin'? Registered User regular
    I was judiciously using wchar_t too to save from the random smattering of MFC types. I gave up at this point though. On the plus side my interfacing DLL is functioning properly in place of the old one that was broken and good golly do I not want to deal with MFC ever again.

    It's like throwing up, you go 10 years without doing it and suddenly you're like hey why not, and then you realize that's a terrible idea.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • bowenbowen How you doin'? Registered User regular
    And for some reason it wouldn't give me an ASCII string no matter how hard I tried to get it without the DBVariant, seriously fuck you MFC, fuck you.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • wildwoodwildwood Registered User regular
    @Cantido - check out this link - stackoverflow.com/questions/6969841/adding-enum-type-to-a-list - there's an example response partway down that shows you how to declare the ArrayList so that you can add any kind of enum to it. Hopefully that helps.

    (All I did to find that link was google "java enum arraylist", and scan the results for answers from StackExchange. Develop your google-fu... feel the power... :) )

  • Jimmy KingJimmy King Registered User regular
    Saeris wrote: »
    When did Perl introduce the /r modifier on substitution? 5.8.8 doesn't seem to recognize it.
    Itl ooks like 5.14 is the first official release with it according to http://www.effectiveperlprogramming.com/blog/659

  • CantidoCantido Registered User regular
    Solid Steel Podcast, Blind Guardian, Amon Amarth, Portal (the Aussie cthulu band, not the game
    wildwood wrote: »
    @Cantido - check out this link - stackoverflow.com/questions/6969841/adding-enum-type-to-a-list - there's an example response partway down that shows you how to declare the ArrayList so that you can add any kind of enum to it. Hopefully that helps.

    (All I did to find that link was google "java enum arraylist", and scan the results for answers from StackExchange. Develop your google-fu... feel the power... :) )

    Okay, that's what my problem was: you can't ArrayList an enum, instead that example shows that you can make an ArrayList of strings composed of enum values. That's fantastic, and just what I need.

    3DS Friendcode 5413-1311-3767
  • VerboseVerbose That one guy over there. That guy. Registered User regular
    edited April 2012
    Does anyone know anything about Java Applets? I'm making a few board games as part of a project for school, and I am tearing my hair out right now trying to understand why my applet wont display any graphics. On a small testing scale I can get it do draw grids and pieces easily enough but when I implement it into my game program it just doesn't display anything.
    If anyone can help, I can provide more details.

    Verbose on
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    edited April 2012
    Jimmy King wrote: »
    Saeris wrote: »
    When did Perl introduce the /r modifier on substitution? 5.8.8 doesn't seem to recognize it.
    Itl ooks like 5.14 is the first official release with it according to http://www.effectiveperlprogramming.com/blog/659

    Oh wow. I didn't think something as useful as /r would be so new. On the other hand, maybe I'm missing some more common idiom for what I'm doing.

    What's the usual Perl way to pull a single pattern match? For instance, if you have the string "abcdef", how would you get the single capture from the pattern "bc(.)e" as a return value, such that you can use it when defining a hash?

    In Lua this would be:
    local hash = { d = string.match("abcdef", "bc(.)e") }
    

    But the closest I've gotten in Perl 5.8.8 is two lines:
    my ($d) = ("abcdef" =~ m/bc(.)e/);
    my $hash = { d => $d };
    

    I'm having surprisingly little luck Googling for this. Isn't this Perl's forte?

    Saeris on
    borb_sig.png
  • InfidelInfidel Heretic Registered User regular
    Saeris wrote: »
    Jimmy King wrote: »
    Saeris wrote: »
    When did Perl introduce the /r modifier on substitution? 5.8.8 doesn't seem to recognize it.
    Itl ooks like 5.14 is the first official release with it according to http://www.effectiveperlprogramming.com/blog/659

    Oh wow. I didn't think something as useful as /r would be so new. On the other hand, maybe I'm missing some more common idiom for what I'm doing.

    What's the usual Perl way to pull a single pattern match? For instance, if you have the string "abcdef", how would you get the single capture from the pattern "bc(.)e" as a return value, such that you can use it when defining a hash?

    In Lua this would be:
    local d = { capture = string.match("abcdef", "bc(.)e") }
    

    I'm having surprisingly little luck Googling for this. Isn't this Perl's forte?

    I don't think I'm understanding you right, can you explain again or give a different example?

    OrokosPA.png
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    edited April 2012
    Yeah, I edited in some more details. Basically, I'm trying to combine those two Perl lines above into one, like in the Lua example, but I don't know how to get a scalar return value out of that pattern match. I can only get it to return either a list (as it does now, with the surrounding parentheses) or the number of matches (without the parentheses).


    edit: Oh, duh. I didn't even realize you could subscript an anonymous array context:
    my $hash = { d => ("abcdef" =~ m/bc(.)e/)[0] };
    

    That works exactly as I was hoping it would.

    Saeris on
    borb_sig.png
  • InfidelInfidel Heretic Registered User regular
    edited April 2012
    dp

    Infidel on
    OrokosPA.png
  • InfidelInfidel Heretic Registered User regular
    edited April 2012
    Saeris wrote: »
    But the closest I've gotten in Perl 5.8.8 is two lines:
    my ($d) = ("abcdef" =~ m/bc(.)e/);
    my $hash = { d => $d };
    

    I'm having surprisingly little luck Googling for this. Isn't this Perl's forte?

    Does something like this work?
    my %hash = ( "d" => ("abcdef" =~ m/bc(.)e/g)[0] )
    

    Infidel on
    OrokosPA.png
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    This was one of those cases where just the act of describing the problem in writing helped to solve it. Thanks!

    What a nifty little language, though. Hard to believe that something as ugly as PHP was "inspired" by it.

    borb_sig.png
  • GnomeTankGnomeTank What the what? Portland, OregonRegistered User regular
    Have you seen any bad Perl? Because from that post, I don't think you have.

    Should we burst his bubble now guys, or let him marinate in it for a while before we link to the Perl obfuscation competition?

    Sagroth wrote: »
    Oh c'mon FyreWulff, no one's gonna pay to visit Uranus.
    Steam: Brainling, XBL / PSN: GnomeTank, NintendoID: Brainling, FF14: Zillius Rosh SFV: Brainling
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    Indeed, I fear I'm unindoctrinated in the horrors of the language. I imagine that will come crashing down upon me soon enough.

    borb_sig.png
  • Jimmy KingJimmy King Registered User regular
    admanb wrote: »
    At least that's the best way for a "we don't have enough money..." situation to go.

    Yeah, that's how I try to look at those things. I don't care if you ever use the code I write or not as long as you're willing to pay me to keep writing it.

  • Jimmy KingJimmy King Registered User regular
    Saeris wrote: »
    Indeed, I fear I'm unindoctrinated in the horrors of the language. I imagine that will come crashing down upon me soon enough.
    I spent about 5 years as a full time Perl developer. I love Perl. Well written Perl is awesome. Bad Perl is a thing of horrors that you cannot imagine, though. It's also really easy to accidentally write bad Perl because it has so much awesome voodoo that is easy to abuse and assume everyone will be able to follow.

  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    edited April 2012
    It is important to distinguish between languages like Perl (and C) which is a fine language that makes it easy to do bad things, and PHP, which is a bad language.

    admanb on
  • Jimmy KingJimmy King Registered User regular
    Yeah, definitely. Some languages, like PHP, are just poo. I die a little inside every time I have to go do some nonsense in PHP at work. It's being phased out, but for now there's a bit there... on Windows IIS servers, just to make it extra fun.

  • EvigilantEvigilant VARegistered User regular
    edited April 2012
    I'm having difficulty solving this. Without having to copy all the code, this is what I understand to be the basics:
    Socket clientReader = new Socket(//predetermined port that server is listening to);
    Socket clientWriter = new Socket(//predetermined port that server is listening to);
    //in client
    ObjectInputStream in = new ObjectInputStream(clientReader.getInputStream());
    run(){
      while(true){
        String message = (String)in.readObject();
        System.out.println(message);
      }
    }
    
    
    //server
    Socket serverReader = new Socket(//client write socket);
    Socket serverWriter = new Socket(//client read socket);
    //in server
    sendMessage(String message){
       ObjectOutputStream out = new ObjectOutputStream(serverWriter.getOutputStream());
       out.flush();
       out.writeObject(message);
    }
    
    
    //service fetcher
    Socket ServiceFetchWrtier SFW = new Socket(//server reader socket);
    Socket ServiceFetchReader SFR = new Socket(//server write socket);
    
    //In service fetcher
    sendMessage(String message){
        ObjectOutPutStream out = new ObjectOutputStream(SFW.getOutputStream());
        out.flush();
        out.writeObject(message);
    }
    
    Will that print out service fetcher's message to client? My question then is, how would I take the input from the client and pass it to a module the service fetcher has fetched and executing and awaiting input? Is the answer to pass along serverReader and ServerWriter sockets to a module that's being executed and use those for input and output? So a constructor would look like:
    //Service Fetcher Constructor
    public ServiceFetcher(Socket serverReader, Socket serverWriter, int command){
      ObjectInputStream in = new ObjectInputStream(serverReader.getInputStream());
      ObjectOutputStream out = new ObjectOutputStream(serverWriter.getOutputStream());
      out.flush();
    
      if(//command == service number){
            service(serverReader, serverWriter);
       }
       in.close();
       out.close();
    }
    

    Would something like that work?

    Or do I just put them all in a package and pass the server object to the service fetcher, and then do something like:
    Public ServiceFetcher(Server MAINSERVER, int command){
      this.server = MAINSERVER;
      if(//command == service number){
          service(MAINSERVER);
          sendMessage("Executing service: "+command);
      }
    }
    sendMessage(String message){
       server.sendMessage(message);
    }
    

    Evigilant on
    XBL\PSN\Steam\Origin: Evigilant
  • SaerisSaeris Borb Enthusiast flapflapflapflapRegistered User regular
    edited April 2012
    admanb wrote: »
    It is important to distinguish between languages like Perl (and C) which is a fine language that makes it easy to do bad things, and PHP, which is a bad language.

    I cannot resist linking to PHP: a fractal of bad design.
    I can’t even say what’s wrong with PHP, because— okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there.

    You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes.

    You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.

    You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever.

    And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools.

    Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.

    That’s what’s wrong with PHP.

    For extra fun, search that page for "INT_MAX".

    Saeris on
    borb_sig.png
  • Mike DangerMike Danger "Diane..." a place both wonderful and strangeRegistered User regular
    So, here's where I'm at right now with this project.

    I have a little Ruby program that takes in two files: a "degree" spec and a list of the user's courses. A degree is broken up into requirements. A requirement has a name ("200 level courses"), a quantity (4), and a list of courses which can satisfy that requirement. (CSCI210, CSCI250, CSCI280, etc) The Ruby program reads the degree spec and the list of courses and figures out what's left.

    My vision is that the user comes to the app, picks their major, and then clicks a button for each course they've completed in the major, then gets a message showing them what they have left to do.

    So, looking at what I have set up for myself, it seems like I'm going to need to be storing stuff in a database for later retrieval? Show the page for the user, hit the DB to get the degree spec, display the course options, do the logic, display the result.

    Steam: Mike Danger | PSN/NNID: remadeking | 3DS: 2079-9204-4075
    oE0mva1.jpg
  • admanbadmanb unionize your workplace Seattle, WARegistered User regular
    Yup. Luckily, adding DB tables/Models to Rails is super easy and elegant.

  • Mike DangerMike Danger "Diane..." a place both wonderful and strangeRegistered User regular
    One more Rails question: so I want to do a bunch of migrations that will set up a table for each degree. Is there a way to do this without having to type "rails generate model" over and over again? I tried doing this, but it didn't work:
    02:07: ~/rails_projects/specs $ rails console
    Loading development environment (Rails 3.2.3)
    >> fil = File.new("list.txt", "r")
    => #<File:list.txt>
    >> fil.each_line do |l|
    ?> rails generate model #{l.strip} name:string quantity:integer courses:array
    >> end
    NameError: undefined local variable or method `model' for main:Object
    	from (irb):3
    	from (irb):2:in `each_line'
    	from (irb):2
    

    Steam: Mike Danger | PSN/NNID: remadeking | 3DS: 2079-9204-4075
    oE0mva1.jpg
  • InfidelInfidel Heretic Registered User regular
    The schema is the same for each degree so you shouldn't have a bunch of tables storing the same kind of thing on this scale. Add a degree ID and have them in one table?

    OrokosPA.png
  • bowenbowen How you doin'? Registered User regular
    @Evigilant

    Kind of, get rid of the two sockets and get two separate streams from one socket. Then, after a client connects, wait until there's data. Check how many bytes, read it, Append it to an array or string until you get a delimiter -- you need a delimiter of sorts to know your message is done -- and then do whatever you need to do when you reach that delimiter (call a function and pass the string maybe?). I usually use something like 0xff for the delim which isn't really an ascii character (assuming we're using ascii and not unicode).

    Sending binary data becomes the fun part.

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
This discussion has been closed.