Wednesday, April 13, 2011

Auto-hide panel in QT or WxWidgets

I am looking to find a way to have a docked panel that would be similar to the panels within visual studio.

Essentially a panel that can be set to auto hide or can be pinned open.

Possibly this question was a bit vague. What I am looking for is essentially this product

Please leave a comment if I am missing details as I would like this question solved. I have searched google a fair bit and have not been able to find a possible solution. If worse comes to worse I will end up using a shortcut to hide and unhide the side panel.

From stackoverflow
  • check out the AUI demo in wxWidgets.

    Victor T. : @braindead the wxAUI doesn't have that auto-hide/pinning feature the OP is looking for.
  • Qt4 has QDockWidget class, maybe that's what you're looking for?

    http://doc.trolltech.com/4.5/qdockwidget.html

  • Qt sadly doesn't support this. I've bugged them and others but got no word. I'm writing my own to doing this.

IIS Hang Troubleshooting

I'm running a website on IIS 6 (Windows Server 2003) that hangs occasionally.

Timeline:

Released to the wild, website ran fine for 3 days.

Website hangs on every request until the website is stopped and started.

Website runs for 2 weeks with no problem.

Website hangs on every request until site is restarted.

We see a few application log entries before hang starts: Faulting application w3wp.exe, faulting module unknown, version 0.0.0.0 fault address -------.

The application installed on the website is written in .Net 2.0.

Can anyone please guide me on troubleshooting this issue? Thanks!

From stackoverflow
  • Your best bet might be to use adplus to capture a memory dump of the hanging w3wp process, and then use windbg + the sos extension to try to determine the cause of the hang.

    You can get adplus and Windbg here: http://www.microsoft.com/whdc/devtools/debugging/default.mspx

    Also, Tess Ferrandez' blog is an absolute goldmine of information on learning how to analyze memory dumps with Windbg. She even has a set of labs you can go through targeted toward specific scenarios.

    http://blogs.msdn.com/tess/default.aspx

  • There are many reasons why this could happen. A couple of years ago, I had this happen on web project in production, and it took a call to Microsoft to fix it. I wish I could give you specific details but this is what I remember.

    .NET caches the folders in your web application. There is a registry key on the server (cannot remember where ) that sets a folder limit (believe it or not). The limit was set to 150 folders by default. If you had more than this many folders in your web application, and you tried to access the 151st folder, it would crash IIS.

    Yes this sounds crazy but trust me, I spent weeks with Microsoft until we found out the cause of the crash. The answer at the time was to up the limit in the registry and reboot the server. This was a couple of years ago, and I hope that this was fixed in later updates, but I offer this to you just in case you are using an older version of Server 2003.

    I am sorry I cannot provide more specific details, but I just want to let you know my experiences just in case this sounds like your issue.

  • make sure IIS is set to be able to recycle its process automaticly, might help to fix the issue if it is a memory leak. (well ok cope with the problem not fix)

    My advice is to give you app its own application pool, so you are 100% sure that its the appication you think pulling the server down, what dose the application log say when this happens?

    From the information you have given it sounds like its a memory leak or open db connection / thread issue.

    P.s If you are using N2 there was a known issue that when IIS recycled it wouldnt come back up.

Linq: IsNot in Object collection

Dim goodCustObjList As New List(Of CustomerObj)
goodCustObjList = DataBLLModule.GetCustomerRecordList(String.Empty)
Dim custList = From t In goodCustObjList _ 
               Where t.ID.ToString() IsNot Guid.Empty.ToString() _
               Select t

I have a list of CustomerObj and if the ID (GUID) is not empty then i want to select that object. I did a similar query but the condition is on another object's property (integer) that match if it is 1 or 2 then select it.

Can someone point out what i'm doing wrong on the above linq statement? if you going to test an condition in linq. Isn't IsNot is the correct statement to test that condition?

Jack

From stackoverflow
  • "IsNot" in VB means to test whether two object references point to different objects. I'm not sure why you are getting this for this particular syntax. Can you post the definition of CustomerObj?

    What you really want to be doing though is comparing the .ID property directly.

    Where t.Id <> Guid.Empty
    

    This is the most reliable way of comparing GUID values. Comparing their String values is much slower and can be thrown off if you accidentally do a case sensitive comparison.

    Tom Anderson : Quite right on that comment, this is the proper way.
    Jack : that's it. Thank for the help

In XSLT, how can you get the file creation/modification date of the XML file?

I would like to know the file creation/modification date of the XML file currently being processed by my XSLT code.

I am processing an XML file and producing an HTML report. I'd like to include the date of the source XML file in the HTML report.

Note: I am using C# .NET 2008 and using the built-in XslCompiledTransform class. I have since found a solution (separate answer) using input from other answers here. Thanks!

From stackoverflow
  • The creation/modification date must be written into the XML file, otherwise you cannot find it out, unless you communicate somehow with the filesystem.

    This question is somewhat related: xslt-how-to-get-file-names-from-a-certain-directory

  • The only things that XSLT has access to are nodes of the source tree, nodes in documents read in via the document() function, nodes in the XSLT template itself (again via the document() function), and values passed in to the transform as arguments.

    So if you want the filename and its creation/modification date to be available to your transform, you have to put them in one of those places.

    It's possible to implement XSLT extension methods to do this, depending on what platform you're using, but that would be my last choice.

  • After suggestions from Kaarel and Robert, I was able to reach the following solution:

    Get the file modification date in C# and pass it to the XSLT processor as follows:

    XmlTextWriter tw = new XmlTextWriter(htmlPath, null);
    tw.Formatting = Formatting.Indented;
    tw.Indentation = 4;
    
    XsltArgumentList args = new XsltArgumentList();
    FileInfo fi = new FileInfo(xmlPath);
    args.AddParam("FileDate", string.Empty,
       fi.LastWriteTime.Date.ToShortDateString());
    
    XslCompiledTransform xslt = new XslCompiledTransform();
    xslt.Load(xsltPath);
    xslt.Transform(xmlPath, args, tw);
    tw.Close();
    

    Then in the XSLT code, define and access that argument as a param as follows:

    <xsl:param name="FileDate"/>
    
    <xsl:text>Revision Date: </xsl:text>
    <xsl:value-of select="$FileDate"/>
    

Dynamically adding user controls registered in web.config‏

So I'm working on a project that has all its user controls registered in its web.config file (which seems very clean and tidy)

So far so good (here comes the problem) however I'm trying to dynamically create and add user controls to a page. These user controls fire events that need handling.

Ordinarily that wouldn't be a problem: You just register the control in the page, load the control, cast it to the correct type, and assign the event handlers, add it to the page, sit back and let the magic happen, easy peasy.

But I can't reference the control's type when the control is registered in the web.config, which means no cast, which means no event handling!

Weirdly you can reference the type if you add the usercontrol to the page at design time!

There must be a way round this (without having to register the control on the page, or add a control at design time), what on earth am I missing?

From stackoverflow
  • By saying : "you can reference the type if you add the usercontrol to the page at design time"

    Do you mean it adds an <%@ Register %> Directive at the top of the page ?

    Or maybe, it adds a using / Imports (depending on you using c# / vb.net) clause in your source document ?

    Because, to be able to cast to your control type, you normally need to import the namespace in the codebind. Maybe this is just what is missing.

    Wilfred Knievel : No that's the weird thing, the registration is done in the web.config () so there isn't any need for <%@ Register %> directive on the page. If you drag your user control on the page the everything just starts working (doesn't add a <%@ Register %> or an includes)
  • The <controls> section in web.config and the <%@ Register %> directive are the same thing (with the small exception that entries in web.config apply to the whole application). They allow you to add design-time controls to a web form.

    If you want to add controls to a page dynamically, use the LoadControl function to get an instance of your control. Given a control with a class name of "Header", the following will load a control, set a property, and add the control to the form named, "form1":

        Dim head As Header = LoadControl("~/Controls/Header.ascx")
        head.Text = "Some text..."
        Me.form1.Controls.Add(head)
    
    Wilfred Knievel : That's exactly what I expected, but I get "The type or namespace name 'Header' could not be found (are you missing a using directive or an assembly reference?)" (the weird thing is if I add the tag for a header control to the page [just the ] it will work fine!)
  • It's been a while, but I think I've seen this type of behavior in ASP.NET when a project is a Web Site and not the Web Application. As far as I remember, the Web Site compiles each page into its own assembly and with no common name space and regardless of config requires the <%@ Register %> directive. If you don't, you get the exact error of missing an assembly reference.

    I would have to test to be sure...

    Martin : You're right about the website compiling each page into it's own assembly. If you register controls in the web.config, it should be fine. However, maybe the controls have to be defined in a separate assembly for it to work. At work, we use telerik's controls in a website project and it works fine.
    Wilfred Knievel : You're absolutely right, just did a quick test and it worked fine in a Web application and failed miserably in a website. Thanks for that!
  • I am trying to do the same thing also. I want to be able to do something like:

    Dim head As Header = LoadControl("MyHeaderTagPrefix", "MyHeaderTagName")
    head.Text = "Some text..."
    Me.form1.Controls.Add(head)

    I would expect to be able to retriev the control using those 2 values at runtime (aka Dynamically).

    Any ideas?

How to find out user name and machine name to access to SQL server

My work company has a MSSQL server 2005. I have two questions about finding out current log user and any way to send out a warning message:

First question is if there is any T-SQL or SP available to find out current login user name and machine name. If the user is using SQL server sa name to remotely access to SQL server, is there any way to find out that user's windows name (the name to log to the windows)?

My next question is that if I can get the user name or id, is there any way to send out a warning message such as "currently SQL server is clean up or backup, please do not log in at this time". I guess it may be difficult. I may have to send an email out to the user.

The SQL server is only accessible in the company. The SQL server has a list of users as login users: windows users, SQL users and sa.

From stackoverflow
  • SELECT SUSER_SNAME(), HOST_NAME()

    I the connection is "sa" (or any other SQL login) then you can't find the domain/windows user name. SQL Server only knows it's "sa".

    HOST_NAME may not be reliable either, it can be set in the connection string. MS Access for example does not support this.

    You could backtrack via client_net_address in sys.dm_exec_connections and match MAC address to IP and find out who is logged on...

    John Sansom : +1:Well thought out answer.
  • An easy way to find out both host and user is

    EXEC sp_who2;
    

    where you get some other information that can be good to know, as if the user is active and so on... It does not resolve the issues that gbn announced.

  • For a more visual representation of grabbing a list of users and what Databases they are in open up Microsoft SQL Server Management Studio. In there you can click on the Management folder then Double Click on Activity Monitor.

    This will give you a graphic display similar to running sp_who in a query. The user tab will give you a clue to what type of account they have.

    You can also run quick filter on that list to narrow down your search. e.g. via a database.

  • Thanks for all your suggestions first. I tried all the methods and I think Joakim Backman's method meet my need. Here is summary of what I find out.

    • Query of sys.syslogins only list login information. The accdate does not give the current login user timestamp. I tried to login from another application to my SQL and this query does not list the login.
    • SELECT SUER_SNAME(), HOST_NAME() only list one user on SQL server. For example, I login in as my name to SQL server. The result this query only list my name and machine name. This query does not list current user on the SQL server.
    • exec sp_who2 lists information I need. It lists current user name machine name, active status, db name users access, and command used.

    In order to get the information I use in SP, I have to filter and join the information with other tables such as emails. Here is the codes I use:

    DECLARE @retTable TABLE (
     SPID int not null
     , Status varchar (255) not null
     , Login varchar (255) not null
     , HostName varchar (255) not null
     , BlkBy varchar(10) not null
     , DBName varchar (255) null
     , Command varchar (255) not null
     , CPUTime int not null
     , DiskIO int not null
     , LastBatch varchar (255) not null
     , ProgramName varchar (255) null
     , SPID2 int not null
     , REQUESTID INT
    )  
    
    INSERT INTO @retTable EXEC sp_who2  
    
    SELECT Status, Login, HostName, DBName, Command, CPUTime, ProgramName -- *
      FROM @retTable
      --WHERE Login not like 'sa%' -- if not intereted in sa
      ORDER BY Login, HostName
    
  • I have use the above sp that recommend by David. It works great for my development Database, but can't be run at Live Database.

    Is this due to access rights or security issues?

Extension of question many to many relationships in same table.

I got a single table and it contain 4 fields

Id|Hospital|   Doctor|patient

1     A        D1      P11

2     B        D6      P61

3     A        D2      P21

4     A        D1      P12

5     B        D7      P71

6     B        D6      P62

7     B        D6      P63

Doctors are unique to the Hospital. They don't work in other hospitals. Patients are unique to the doctor they don't visit any other doctor. Each hospital is having multiple Doctors.

If you observe there are multiple patients for each doctor.

Now the question is: How can I get "only one patient" related to the each doctor. It can be any patient from the record.

I am looking forward to see some thing like this

 Hospital Doctor Patient
  A       D1      P11

  A       D2      P21

  B       D6      P61

  B       D7      P71

I got the answer like select Hospital,doctor, max(patient) from table GROUP BY Hospital,Doctor ORDER BY Hospital,Doctor;

How to get the id also which is unique from the above table like.

id Hospital Doctor Patient
 1   A       D1      P11

 3   A       D2      P21

 2   B       D6      P61

 5   B       D7      P71

I am very sorry to repost this question.

From stackoverflow
  • Try something like:

    select Id,Hospital,Doctor,Patient
      from table
      where Id in (select max(t.Id) from table t group by t.Hospital,t.Doctor)
      order by Hospital,Doctor;
    
    Giridhar : Your answer is accurate sweet and short.Thank you
  • SELECT  m.*
    FROM    (
            SELECT  (
                    SELECT  id
                    FROM    mytable mi
                    WHERE   mi.hospital = md.hospital
                            AND mi.doctor = md.doctor
                    LIMIT 1
                    ) AS first_patient
            FROM    (
                    SELECT  DISTINCT hospital, doctor
                    FROM    mytable
                    ) md
            ) mo, mytable m
    WHERE   m.id = mo.first_patient
    
    Giridhar : This script says that right paranthsis is missing at SELECT ( SELECT id FROM mytable mi WHERE mi.hospital = md.hospital AND mi.doctor = md.doctor LIMIT 1 ) AS first_patient
  • You might look at breaking things into three tables: Hospitals (with Primary Key id, and the Hospital field), Doctors (with someother PK, a Foreign Key of Hospitals, and the Doctor field) and Patients (with someother PK, a Foreign Key of Doctors, and the Patient field). Then your statement would look something like:

    SELECT H.Id, H.Hospital, D.Doctor, Max(P.Patient)
    FROM Hospitals H
    INNER JOIN Doctors D ON H.Hospital = D.Hospital
    INNER JOIN Patients P ON D.Doctor = P.Doctor
    ORDER BY Hospital, Doctor
    
    Giridhar : I dont have the control on table.
    Lance Roberts : OK, then you'll have to use the other answers.

What can influence Delphi executable size?

I have the very same delphi version, bpls, components, everything. And yet in three machines the resulting executables are different in size. What else can influence in the size of the exe?

In my machine I get this size (Vista 6.0.6001):

4.547.584 bytes

In my colleague's machine, he gets (XP 5.1.2600 SP3):

4.530.688 bytes

In a third colleage, he gets: (XP 5.1.2600 SP2)

4.527.104 bytes

Does the OS version influence in the compiled exe size?

From stackoverflow
  • With Delphi/BCB these are a few factors that can influence size:

    Your Build Configuration: Release Mode does not link in the debug section into the EXE (by default) so is smaller. also you may get a boost from code optimization.

    Linking with Dynamic RTL: If enabled you EXE will be smaller but you will require the external libraries to be available.

    Building with Runtime Packages: If enabled, you dynamically link to the runtime packages you use instead of linking them directly into your EXE. This can result in the largest size differences.

    Their are other factors but the above tends to be the main ones I come across.

    Roddy : Steve - that's a great answer to a totally different question ;-)
  • The differences almost certainly come from different compiler settings between the machines. For instance, turning Range Checking on or off will slightly alter the resulting size of the executable.

    One of the nice things about the more recent versions of Delphi is the use of MSBuild, which can easily ensure that the settings for any given build are the same.

    Ricardo Acras : Our DPR files are the very same, for sure. Range checking is a project option. I can't see any IDE option that could interfere in the size of the resulting executable.
  • It would seem that it is configuration differences, or if maybe you have different versions of components installed between the three machines. I would suggest creating a blank form and trying it on all 3 after you verify that the build settings are the same. If that is the same then add some 3rd party components until you find the one that is different.

    Additionally you may have a different version of Delphi (major or minor/update version).

    Ricardo Acras : Thanx Jim. Will try it and post results ASAP
    Ken White : Sorry, Jim. Not correct. See my post for links that explain why.
    Jim McKeeth : Actually Ken, it could be both, but I was not aware of the issue you pointed out.
  • IIRC, re-compiles after making minor changes may also leave cruft laying around - one fo the side effects of the smart compiler, I guess :}

  • Actually it's much more interesting than than.

    Even re-building the same application on the same machine, several times in succession, making absolutely NO changes to the configuration whatsoever in between compiles, produces executables of slightly different sizes. I built a particular project 10 times and obtained 10 (!) different executable sizes - a different size every time!

    I've noticed that the phenomenon only occurs on projects of sufficient size/complexity, though.

    If you do this on a relatively simple project, the executable will be the same size, even though there will still be internal differences (if you do a binary compare). I don't have the time to investigate this right now, but I am mildly curious.

    Notice that merely doing a compile, i.e. effectively just re-linking the application, does not change the size of the resulting executable, but it does change its content (binary files generated are not identical).

  • Actually, it's a issue that's been around for quite some time. See

    CodeGear Quality Control

    Borland Delphi newsgroups

    Recent discussion of this on Delphi newsgroups (http view).

    It has absolutely nothing to do with differences in component installs or anything like that; in fact, the last reference mentions something to do with timestamps that are inserted into the application on each compile/build. Also, if you're doing a build and are including version info, and have the build number set to autoincrement, this will cause binary differences as well.

  • Hmmm...

    SizeOf(XPSP2.exe) < SizeOf(XPSP3.exe) < SizeOf(Vista.exe)

    Conclusion:

    The later the version of Windows, the more "filler" is randomly inserted to add credibility. If it takes more space then it must be more powerful, and it was probably coded by the best engineers in the world! :-) (sorry - I've been working at Microsoft for too long!)

    mjustin : this is definitely a statistical trend :)

Using Jasper Report

I am using JSP/Servlets to integrate the JAsper report tool to generate reports in 5 different formats. After getting the output in the HTML or Excel format, Can we sort the fields of the table so that the page is dynamic? I am not sure how to do this since Jasper is already called using servlet and the data is filled.

From stackoverflow
  • Could you, please, clarify a bit? What exactly do you want to do? If you want to sort the HTML fields of the table, I am afraid, that's not possible. Excel is another matter, as it contains dynamic data.

PowerBuilder for a Java programmer?

A friend of mine uses in his company an ERP software written in PowerBuilder. Unfortunately the (one and only) developer is going into retirement soon. My friend really likes the software and wants to keep using it for at least ten more years, so my friend decided to buy the source code.

He wants to start a business to maintain the software and develop new features. At the moment there are probably about 50 installations of that software out in the wild and he already knows of a bunch of potential buyers.

Now he's searching for a developer and asked me... I did a little C/C++ programming, a bit of VB and a bunch of other languages but in the last years I earned my money by writing Java web applications. From what I read, PowerBuilder looks quite antiquated to me, there are hardly any tutorials out there, no open source frameworks, awkward version control, didn't even read about any test frameworks. People here on StackOverflow say they hope, the language/IDE is dead. Additionally the code I'd maintain is completely undocumented and untested.

Do you think it's possible, for someone who never even heard of PowerBuilder before, to maintain such a software?

EDIT: okay, thanks for your answers. We decided to kick the old application completely and re-write it in an up-to-date-language.

From stackoverflow
  • I worked on powerbuilder quite sometime back, version 6.5 Its quite easy to use and one can compare it to VB. I feel it would be quite easy to maintain an application and do small fixes and enhance the system. There are quite a few companies that still use powerbuilder and maintain old application.

  • Yes, it's possible. Powerbuilder is not a hard language to pick up, particularly if you have used VB already.

    The Powerbuilder community is far smaller than what you may be used to with e.g. Java, but it does exist. The best place (other than SO!) to ask questions are the sybase.public.powerbuilder.* newsgroups.

    For unit testing, try PowerUnit, and for source control, you can use Subversion via PBSCCProxy, TamTam SVN SCC, or PushOK SVN SCC proxy.

    It's been a niche language for a long time now. In my opinion this is due the upfront cost of the tools required, which is essentially blocking anyone new from considering it.

    The future is reasonably bright though: Sybase is flourishing, committed to PowerBuilder, and regularly announcing progress towards version 12, which will be a full .NET language like C# and VB.NET, and will ship with an IDE based on VisualStudio. You will be able to directly migrate your code to version 12, no rewrites required.

    Zerofiz : There will be PLENTY of refactoring to do before going to PB12.
    Terry : The comment about refactoring to go to PB12 is uninformed, I'm afraid. There is nothing intrinsic about PB12 that will require refactoring. I've migrated apps to pre-releases of PB12, even to WPF targets, with no code changes at all. That's not to say *no* changes will be required, say if your app uses features that aren't supported anymore (e.g. right clicks on commandbuttons). That's also not to say refactoring won't be required to leverage new features, but that's true in leveraging almost any new features. Sybase has some good webcast recordings about PB12 worth looking at.
  • Yes, you would certainly be able to learn PowerBuilder. Whether you want to is a question only you can answer, though.

    I used PowerBuilder for many, many years (versions 4 through 9). There were parts I truly liked. It's a great way to build business applications. It's object-oriented and the DataWindow is a wonderful technology.

    But it has its bad points as well. The IDE is archaic. The code editor is simplistic (no code completion, for example). Integration with source control is annoying and the community is pretty small. And it's Windows-only.

    There is a magazine (PowerBuilder Developer's Journal - SYSCON), but it's pretty thin these days. Sybase does appear to have some neat things up their sleeves for future versions of PowerBuilder, however.

    Personally, I liked it enough that I would go back to it if an opportunity arose.

  • Yes, any competent programmer, and even some not-so-competent ones can use PowerBuilder. However, I'd disagree somewhat with one of the earlier answers. It is different from pre-.Net VB in one sense: it supports true OO principles (encapsulation, inheritance, and inclusional polymorphism [but not operational polymorphism via Interfaces as in C# and Java]). Classic VB didn't have inheritance.

    Other answers from Paul Lefebvre and Colin Pickard are correct: PB is still alive though more of a niche language than it used to be, and Sybase is indeed moving it in the direction of .Net. As for source control, PB supports some interfaces (we use it with VSS) but I'm thankful for Colin's nice set of links, which may come in handy in the future.

    Frameworks: the most common one is the PowerBuilder Foundation Class, which Sybase open sourced years ago.

    My caveat to you is this: I said above that people didn't have to be particularly strong programmers to write PB. PB is easy to learn but takes time to master. It had its biggest days in the late 90's, when anyone that could double-click on a Windows icon to launch an app thought they were a programmer. Despite truly supporting OO, most PB apps are not well designed and well written apps. They're usually total hack jobs (a criticism of the lack of experienced developers and immaturity of software development at the time, not of PB itself, which is still a very powerful tool). If you are inheriting a code base that is truly easy to maintain and manage, you are in the minority. PB code can nearly always be classified as legacy code. The good news is that there is plenty of challenge. You will have many quick-win refactoring opportunities and plenty of production support.

  • I started my career as a PowerBuilder developer, but quickly changed to java and python, as soon as I realized PB was almost a dead language.

    Also, even if there are tools that can be used to apply programming "good practices", they are not widely known and somewhat expensive, so I've had to work even without version control (!!), left aside automated testing or continuous integration.

    It is a language in which almost anyone can start to build usable apps in a short period of time and with little training, and the apps are built really fast, in contrast with java, that demands a period of learning until a developer can be productive, and even then, a webapp takes time to be developed.

    But the payback is with maintenance, that quickly becomes a nightmare. Even a minor change in the database like a type change in a database column can destroy every datawindow (the PB ubiquitous data-access component) that refers to it.

    It's pretty much similar to VB, in that as almost anyone can develop applications in it, with very little programming knowledge, the average quality of applications is very low, with unmanageable database coupling and plagued of bad coding practices.

    My advice is not to build a Developer career in such kind of language unless the money justifies it, and in that case, continue training yourself in alternative technologies as a "plan b" to not become obsolete along with the language.

    And always work to keep your coding and problem solving skills "in good shape" as this kind of language does not help in that.

    Zerofiz : You sir, are an idiot.
  • With the risk of sounding biased I think PB is one of the better RAD tools out there and the new version PB12 scheduled next year will make it once again interesting since it uses the VSShell from Visual studio as its new IDE (Intellisense etc). I am currently busy working in the compiler team adding all the .NET goodies to PowerScript that one is used to from C# like delegates, interfaces, attributes etc but still keeping the language simple to use. PB is also one of the few development platforms that provide migration from older to newer versions and the new PB12 is no exception. The applications generated by PB12 will be modern looking using WPF and later Silverlight for post PB12 so I am quite excited. I am not a PB developer per se (C++) but I still think for producing C/S apps fast its hard to beat.

  • It depends on the technical quality of the original application whether migrate to another language is feasible at all.

    BEFORE YOU READ MY "PB IS GOOOD": I'm a PowerBuilder developer since '93. PowerBuilder is very much alive and kicking. Yes a lot of people left the language shortly after the millenium but quite a few have returned later. No I don't earn money selling PB!

    The biggest differentiator between PowerBuilder applications and any other tool is the DataWindow technology. It is such a strong tool in the hands of an knowledgeable developer. Examples: Dynamic creation of optimal SQL for INSERT/UPDATE/DELETE. Close to every property of everything can be an expression using data in the DW buffers. DropDown DWs are so cool. DW and the rest of PB is truly DBMS independent!

    How important is code completion when many of my DataWindows only need 4 function calls anyway?

    • Define DB connection >> dwData.SetTransObject(SQLCA)
    • Read all data from DB >> dwData.Retrieve()
    • Write data to DB >> dwData.Update(true, false)
    • Reset when committed >> dwData.ResetUpdate( )

    My bet: If the original developers knew how to really exploit DataWindows - any estimates you make on migration to Java or C# will not even come close to what will actually happen. If they didn't: The application is just another application that does data binding differently than your new tool.

    What you loose when using PowerBuilder? You need to accept that the 4GL and its VM are designed as they are - no access to the source code of the VM so you can't make your own VM customizations. No turning off the NULL support to increase speed. No changing the event order by rewriting the VM's event manager. 4GL means less lines of code. DataWindow means a lot less LOC. 4GL means less geaky bit tweaking.

    /MicKr- BTW: PocketBuilder is PB for Windows Mobile - cool idea!

    Olvagor : Thanks for your answer! We decided to rewrite the application, but mostly due to the lack of documentation and tests. I took a look at the code and it was a mess. I'd have given PB a chance but not on that code basis...

Reading and writing images to an SQLite DB for iPhone use

Hi All, I'm still new to iPhone Dev so be gentle.

I've set up a SQLite DB that currently reads and writes NSStrings perfectly. The only problem I have now is that I also want to store an image in the database and recall it later. I've read up a bit on using NSData and encoding the image but I'm not entirely sure what the syntax is for what I want to do. Any code snippets or examples would be greatly appreciated.

My current process goes like this: UIImagePickerController -> User Chooses Image from Photos -> chosenImage is set to instance of UIImageView -> Now I want to take this image and store it in the DB

Thanks in advance!

Edit* I should mention this call will eventually be replaced with a call to a remote server. Not sure if this makes a difference as far as performance goes.

From stackoverflow
  • One option (and generally preferred when working in SQL) is to write the image to a file on the system and store the path (or some other kind of identifier) in the database.

    John Fricker : I'm really at a loss as to why anyone would store the binary in the DB. Seems nuts to me. So I think the metadata in the DB is the best case.
    Jeff : Can you show me a code example for something like this? I can see how saving out to a file could be beneficial.
    Jeff : after a few days of googling. I've realized and executed this idea. I'll post some code if anyone needs it.
    diana : Can u please post it ?
    ing0 : This is not always ideal.
  • You'll need to convert the UIImage hosted within your UIImageView into a binary BLOB for storage in SQLite. To do that, you can use the following:

    NSData *dataForImage = UIImagePNGRepresentation(cachedImage);
    sqlite3_bind_blob(yourSavingSQLStatement, 2, [dataForImage bytes], [dataForImage length], SQLITE_TRANSIENT);
    

    This will generate a PNG representation of your image, store it in an NSData instance, and then bind the bytes from the NSData as a BLOB for the second argument in your SQL query. Use UIImageJPEGRepresentation in the above to store in that format, if you like. You will need to have a BLOB column added to the appropriate table in your SQLite database.

    To retrieve this image, you can use the following:

    NSData *dataForCachedImage = [[NSData alloc] initWithBytes:sqlite3_column_blob(yourLoadingSQLStatement, 2) length: sqlite3_column_bytes(yourLoadingSQLStatement, 2)];    
    self.cachedImage = [UIImage imageWithData:dataForCachedImage];
    [dataForCachedImage release];
    
    Jeff : Thanks Brad! I'll give this a try later this afternoon. Looks like it may do the trick though.
    Jeff : I realized this isn't want I wanted to do. Saving the file to a URL on the server is a better way to go.
    Brad Larson : If that works best for application, then that's the way to go. I've stored images in the database when I wanted a single file that I could bundle in an application which would hold some starter data. It made the filesystem a little cleaner.
  • Brad's solution works perfectly =D

    Thanks Brad

  • Writing Image to SQLite DB

    if(myImage != nil){ NSData *imgData = UIImagePNGRepresentation(myImage); sqlite3_bind_blob(update_stmtement, 6, [imgData bytes], [imgData length], NULL);
    } else { sqlite3_bind_blob(update_stmtement, 6, nil, -1, NULL); }

    Reading From SQLite DB

    NSData *data = [[NSData alloc] initWithBytes:sqlite3_column_blob(init_statement, 6) length:sqlite3_column_bytes(init_statement, 6)];
            if(data == nil)
                NSLog(@"No image found.");
            else
                self.pictureImage = [UIImage imageWithData:data];   
    

hide() radio button *and* its text label in jquery

Hi

I am going back over a recent project sorting out accessibility issues and was making sure all form elements had labels. Putting the label text into a tag caused a problem with some kludgy code I had written before.

Basically, if you have a radio button and its label:

<label for="zone_r1"><input type="radio" name="zone" id="zone_r1" value="NY" />New York</label>

And you use jquery to hide it like so:

$('#zone_r1').hide();

The actual button is hidden but not the label text. Originally I made a span for the label text and hid that like so:

<input id="NY" type="radio" name="zone" value="NY" /><span id="nyTXT">New York</span>

and

$('#NY').hide();
$('#nyTXT').hide();

Any ideas? I prefer not to use the kludge and it may not validate with the span in the label, but maybe I am being overly zealous.

From stackoverflow
  • $('#zone_r1').parent().hide();
    

    works for me

  • what about $('label:has(#zone_r1)').hide();

  • For the first radio button, you can hide the actual button and then its parent:

    $('#zone_r1').hide().parent().hide();
    

    For the second case you can hide the button and the "next" sibling:

    $('#NY').hide().next().hide();
    
  • I think this should work for you

    $("label[for=zone_r1],#zone_r1").hide();
    

    This selects the label with the "for" attribute set to the radio button your looking for, as well as the radio button itself, and hides them both

  • You can do this:

    1.) Define the radio button input without a surrounding label.

    2.) Wrap the "option text" (text to the right of the radio button) in a <span>.

    3.) Use this jQuery statement: $("input:radio:not(:checked), input:radio:not(:checked) + span").hide();

    This will select the radio button and the text to the right of the radio button and hide it.

I sold my source code to a client, can I now re-build similar code and sell to someone else?

So we built a website and software for a client, charged our fee and handed over the code.

The client then got a request from another company about the software. The client passed on the request but said since they owned the code they would need to recieve money for it.

I'm thinking there are 2 options here:

  1. Work with the client as requested

  2. We've actually re-built the software, made it much better and use it for other projects. Am i in my rights to sell that direct to the company that enquired about it instead of going through the client?

Any help on this would be much appreciated

From stackoverflow
  • A couple of hours worth of lawyer money would be well spent in this case.

  • It all depends on what your contract with the client said. If you rebuilt what you have now from scratch, you are probably within your rights to sell it again. If you re-used any of the code, the answer may be different.

    Remember that the client doesn't have to be right in order to sue you. If they think you are cheating them, they can sue and make your life miserable. Sometimes it is worth a little money up front to avoid a big cost later.

  • As I see it, you have two options.

    (1) Work with the original client to strike a deal that allows a one-time payment to the original client.

    (2) Talk to a lawyer to see what you need to do to protect yourself if you decide to cut the original client out of the deal completely.

    Both options can be pursued simultaneously.

  • Ethically I see nothing wrong with it. You have handed over all the assets, but you take experience away from that that makes it easier to do it all again, this is normal.

    Legally I think it depends on where you are and what the contract said. Its well worth investing some money in a few hours of lawyer-time.

    Robin : I agree. You did the work, gave them what they paid for. They don't own your right to do similar projects in the future or make a living doing more of the same thing. Just make sure to keep rights to any reusable code for future projects.
  • Probably too late to do anything about this now, but in the future you may wish to license your software to the client rather than sell it or do it as work for hire. You'd need to make sure that your contract stipulates this up front -- that what you are doing is developing software that you will then license them to use.

    @Jon B's advice is worth following in this case.

  • If there is a really strong market for it, try talking them into changing to a license.

    How about you give free upgrade to new versions?

    If on the other hand, they will be a strong piece of your revenue in the short term, just go through them, but lay out some clear rules for future deals.

  • Disclaimer: I'm not an attorney.

    What do you mean by "sold source code"? Did you specifically agree, in writing, to assign the copyright to the client? Or agree, in writing, that you were performing "work made for hire"? If your contract does not specifically state these terms, you may still be the copyright owner, after all.

    If you assigned the rights in the original code to the client, the client may sue you for copyright infringement if you re-create code that copies the old code verbatim or is "substantially similar."

    There may be other issues such as trade secrets of the client that may have been incorporated into the code.

    1. Talk to a lawyer; and/or
    2. Get explicit permission from client. Since the client provided you with the lead, it sounds like they would be amenable to working out an agreement. You could structure it as part of a referral fee paid to the client
    Jen : The language has to be specific and must be in writing for an assignment to be effective -- implicitly agreeing to general business conditions is not sufficient. Most likely, you still own the copyright, but check with atty

utf-8 vs Unicode

I have heard conflicting opinions from people - according to wikipedia, see here

there are the same thing. Are they? can someone clarify?

From stackoverflow
  • They're not the same thing - UTF-8 is a particular way of encoding Unicode.

    There are lots of different encodings you can choose from depending on your application and the data you intend to use. The most common are UTF-8, UTF-16 and UTF-32 s far as I know.

    thomasrutter : This is a nice, short and accurate answer.
    serhio : however, the point is that some editors propose to save the file as "Unicode" OR "UTF-8". So the mention about that "Unicode" in that case is UTF-16 I believe necessary.
  • "Unicode" is a unfortunately used in various different ways, depending on the context. Its most correct use (IMO) is as a coded character set - i.e. a set of characters and a mapping between the characters and integer code points representing them.

    UTF-8 is a character encoding - a way of converting from sequences of bytes to sequences of characters and vice versa. It covers the whole of the Unicode character set. ASCII is encoded as a single byte per character, and other characters take more bytes depending on their exact code point (up to 4 bytes for all currently defined code points, i.e. up to U-0010FFFF, and indeed 4 bytes could cope with up to U-001FFFFF).

    When "Unicode" is used as the name of a character encoding (e.g. as the .NET Encoding.Unicode property) it usually means UTF-16, which encodes most common characters as two bytes. Some platforms (notably .NET and Java) use UTF-16 as their "native" character encoding. This leads to hairy problems if you need to worry about characters which can't be encoded in a single UTF-16 value (they're encoded as "surrogate pairs") - but most developers never worry about this, IME.

    Some references on Unicode:

    Jon Tackabury : +1: excellent references.
    jalf : I think UTF-16 only equals "Unicode" on Windows platforms. People tend to use UTF-8 by default on *nix. +1 though, good answer
    Chris S : If it's relevant, Windows 1252 (ISO 8859-1) is UTF-8 afaik, which most of Europe uses
    Chris S : I'll clarify that it's not a unicode standard but a subset of ISO 8859-1, and implemented as 1 byte unicode
    Jon Skeet : @Chris: No, ISO-8859-1 is *not* UTF-8. UTF-8 encodes U+0080 to U+00FF as two bytes, not one. Windows 1252 and ISO-8859-1 are *mostly* the same, but they differ between values 0x80 and 0x99 if I remember correctly, where ISO 8859-1 has a "hole" but CP1252 defines characters.
    Alan Moore : Some of your sources are out of date: UTF-8 uses a maximum of four bytes per character, not six. I believe it was reduced primarily to eliminate the "overlong forms" problem described by Markus Kuhn in his FAQ.
    Jon Skeet : Alan: I originally had it as 4 (see edits) but then read the wrong bit of the document I was reading. Doh. U-04000000 – U-7FFFFFFF would take 6 bytes, but there are no characters above U-001FFFFF - at least at the moment...
    Alan Moore : Last I heard, the maximum Unicode code point is U+0010FFFF -- so there's even more room to grow. It's going to be a while before we have to graft surrogate pairs onto UTF-32, as the author of the accepted answer seems to think is the case. ;-)
    Jon Skeet : @Alan: Absolutely :)
    thomasrutter : The idea of calling UTF-16 "Unicode" sits uneasily with me due to its potential to confuse - even though this was clearly pointed out as a .NET convention only. UTF-16 is a way of representing Unicode, but it is not "The Unicode encoding".
    Jon Skeet : @thomasrutter: It's not just a .NET convention. I've seen it in plenty of places. For example, open Notepad and do "Save As" and one of the encoding options is "Unicode". I know it's confusing and inaccurate, but it's worth being aware that it's in fairly widespread use for that meaning.
    Jon Skeet : @unwesen: UTF-8 doesn't need surrogate pairs. It just represents non-BMP characters using progressively longer byte sequences.
    Alan Moore : @unwesen: My point was that, unlike UTF-8 and UTF-16, UTF-32 has always been a fixed-width encoding and always will be. Whether it's in the BMP or one of the supplemental planes, every code point is represented by exactly four bytes.
    Alan Moore : As for using "Unicode" to mean UTF-16, you're right, Jon: that's a Microsoft convention rather than a .NET convention, and I hate it too. This stuff is difficult enough to explain without MS exposing all its customers to this blatantly incorrect usage.
  • Unicode only define code points, that is, a number which represents a character. How you store these code points in memory depends of the encoding that you are using. UTF-8 is one way of encoding Unicode characters, among many others.

    serhio : however, the point is that some editors propose to save the file as "Unicode" OR "UTF-8". So the mention about that "Unicode" in that case is UTF-16 I believe necessary.
  • Unicode is just a standard that defines a character set (UCS) and encodings (UTF) to encode this character set. But in general, Unicode is refered to the character set and not the standard.

    Read The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) and Unicode In 5 Minutes.

    gnomixa : great article, thanks!
    serhio : however, the point is that some editors propose to save the file as "Unicode" OR "UTF-8". So the mention about that "Unicode" in that case is UTF-16 I believe necessary.
    Gumbo : @serhio: I know. Although there are three different UTF-16 encodings: The two explicit *UTF-16LE* and *UTF-16BE* and the implicit *UTF-16* where the endianness is specified with a BOM.
  • To expand on the answers others have given:

    We've got lots of languages with lots of characters that computers should ideally display. Unicode assigns each character a unique number, or code point.

    Computers deal with such numbers as bytes... skipping a bit of history here and ignoring memory addressing issues, 8-bit computers would treat an 8-bit byte as the largest numerical unit easily represented on the hardware, 16-bit computers would expand that to two bytes, and so forth.

    Old character encodings such as ASCII are from the (pre-) 8-bit era, and try to cram the dominant language in computing at the time, i.e. English, into numbers ranging from 0 to 127 (7 bits). With 26 letters in the alphabet, both in capital and non-capital form, numbers and punctuation signs, that worked pretty well. ASCII got extended by an 8th bit for other, non-English languages, but the additional 128 numbers/code points made available by this expansion would be mapped to different characters depending on the language being displayed. The ISO-8859 standards are the most common forms of this mapping; ISO-8859-1 and ISO-8859-15 (also known as ISO-Latin-1, latin1, and yes there are two different versions of the 8859 ISO standard as well).

    But that's not enough when you want to represent characters from more than one language, so cramming all available characters into a single byte just won't work.

    There are essentially two different types of encodings: one expands the value range by adding more bits. Examples of these encodings would be UCS2 (2 bytes = 16 bits) and UCS4 (4 bytes = 32 bits). They suffer from inherently the same problem as ASCII and ISO-8859 standars, as their value range is still limited, even if the limit is vastly higher.

    The other type of encoding uses a variable number of bytes per character, and the most commonly known encodings for this are the UTF encodings. All UTF encodings work in roughly the same manner: you choose a unit size, which for UTF-8 is 8 bits, for UTF-16 is 16 bits, and for UTF-32 is 32 bits. The standard then defines a few of these bits as flags: if they're set, then the next unit in a sequence of units is to be considered part of the same character. If they're not set, this unit represents one character fully. Thus the most common (English) characters only occupy one byte in UTF-8 (two in UTF-16, 4 in UTF-32), but other language characters can occupy six bytes or more.

    Multi-byte encodings (I should say multi-unit after the above explanation) have the advantage that they are relatively space-efficient, but the downside that operations such as finding substrings, comparisons, etc. all have to decode the characters to unicode code points before such operations can be performed (there are some shortcuts, though).

    Both the UCS standards and the UTF standards encode the code points as defined in Unicode. In theory, those encodings could be used to encode any number (within the range the encoding supports) - but of course these encodings were made to encode Unicode code points. And that's your relationship between them.

    Windows handles so-called "Unicode" strings as UTF-16 strings, while most UNIXes default to UTF-8 these days. Communications protocols such as HTTP tend to work best with UTF-8, as the unit size in UTF-8 is the same as in ASCII, and most such protocols were designed in the ASCII era. On the other hand, UTF-16 gives the best average space/processing performanc when representing all living languages.

    The Unicode standard defines fewer code points than can be represented in 32 bits. Thus for all practical purposes, UTF-32 and UCS4 become the same encoding, as you're unlikely to have to deal with multi-unit characters in UTF-32.

    Hope that fills in some details.

Does anybody know of a real time sports scores/stats web service?

Does anybody know of a real time sports scores/stats web service?

From stackoverflow
  • If I had to do this, I'd probably consume and parse the Yahoo RSS feeds for score-related posts: http://sports.yahoo.com/top/rss

    They are well-categorized and Yahoo's feeds are pretty reliable. I don't think there is an official API for this information.

    I found several places on the web referring to a developer API for scores posted by InGameNow, but don't find any mention of it on their site: http://www.ingamenow.com/ There's no specific documentation, but Ryan Spoon, a developer there, recommends you contact him personally, as of July of last year: http://ryanspoon.com/blog/2008/07/27/ingamenow-opens-api-for-sports-scores-interaction-what-can-you-do-with-it/

    Edit: I've done a little investigation since I first posted, and getting scores out of the news feeds seems pretty tricky. This looks like some pretty commercially valuable information that no one wants to offer a free universal feed for. Current best advice? Screen scrape Yahoo sports score pages.

    Edit2: The UPI feed does look very pareseable for scores. What's the usage case here? You trying to build something commercial? Looks like you could easily find yourself on the wrong end of someone's terms of service.

    CSharpAtl : yeah the terms of service is what I am afraid of
    danieltalsky : Still, you could have at least upvoted my answer! ;)
  • Reuters has an online service for sports. You might also check the other wire services, such as UPI which has an RSS feed that appears to include scores.