Sunday, March 22, 2015

Android Studio doesn't like it when you rename and commit with git

Android Studio seems to handle Github/git a lot better than Eclipse's plugin for git does.  However, even Android Studio can get confused at times.

This issue was caused when a new uncommitted java class was renamed to change capitalization on windows.  I suspect it MAY have something to do with the fact windows is not case sensitive on files, but perhaps github is.

Story:
Today I created a class named [entity] which I realized I accidently didn't capitalize the first letter.  Android Studio prompted me to add it to git and I said yes.  Later I renamed the class correctly as [Entity], and eventually tried to commit the change.

Android Studio and Git reported the following error:
Error:error: pathspec 'core/src/com/twojeremys/merge/entity/Entity.java' did not match any file(s) known to git.
error: pathspec 'core/src/com/twojeremys/merge/entity/Projectile.java' did not match any file(s) known to git.

To fix this issue, I had to reset to head with the steps below:

  1. Backup the files first:
    1. Right-click one of the files and chose "Show in Explorer".
    2. Make copies of any files that have changed or the entire project to be safe.
  2. In Android Studio
    1. Delete all conflicting/erroring objects.
  3. VCS -> Git -> Reset Head
    1. WARNING: This will reset everything to the last time you did a commit to head.
  4. Once this is complete, just to be sure:
    1. Close the project, close Android studio, then reopened both.
  5. Create new classes to replace the deleted conflicting objects with the correct name.
    1. Replace the contents of these files, or copy/paste the backup files into the folder.
  6. Commit and push your changes now, and it should work.

If that doesn't work, good luck, I wasted 24 minutes on this ridiculous issue.

Saturday, March 14, 2015

mysql-js session.find composite key

[Initial stub post, clean up later]


Today while playing with mysql-js, Jeremy and I had a table that had a composite key (two columns for 1 key).  We tried a few ways to pass in the values to session.find, yet none of them worked.

After reviewing the code for mysql-js on Github, we determined that the two keys needed to be passed in via JSON format.

Find Command:
session.find(<tableObject>, <key[s]>, <callback method>);

Example with single column key:
session.find(Employee, '110183', onFind);

Example with Composite key:
To find employee 110183 who is the manager for the department d003 the following code works:

session.find(deptMan.DepartmentManager, {dept_no:'d003',emp_no:'110183'}, onFind);

The key is formatting the keys like this:  {dept_no:'d003',emp_no:'110183'}