Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use JOIN? #608

Closed
calraiden opened this issue Jan 1, 2017 · 3 comments
Closed

Can I use JOIN? #608

calraiden opened this issue Jan 1, 2017 · 3 comments

Comments

@calraiden
Copy link

Hi, I'm starting in the ionic and would like to use with sqlite, but don't found examples with JOIN.
Is it possible?

Example:

var query = "SELECT b.name, c.number, v.number, v.text, v.id, v.chapter_book_id, v.chapter_id, v.chapter_testament_id " +
" FROM verse AS v JOIN book AS b ON b.id = v.chapter_book_id " +
" JOIN chapter AS c ON c.id = v.chapter_id " +
" LIMIT 1";
$cordovaSQLite.execute(db, query, []).then(function(res) {
	if (res.rows.length > 0) {
		var n = res.rows.item(0);
		console.log(n);
	}
}, function(err){
	console.log(err.message);		
});
@calraiden
Copy link
Author

Sorry, I was wrong.

I was trying to join, but it was closing the app. I thought it was because of the join, but the problem was encoding iso8859-1.

After several tests, I found a bug and switched encode to UTF8 in the database.

Now, join working very well.

		var query = "SELECT b.id, b.name, b.symbol, b.number, b.chapters, b.testament_id, b.keywords_id, k.color_background AS keycolor FROM book AS b LEFT JOIN keywords AS k ON k.id=b.keywords_id ORDER BY b.id ASC";
		$cordovaSQLite.execute(db, query).then(function(resultSet) {
			if (resultSet.rows.length > 0) {
	            for(var x = 0; x < resultSet.rows.length; x++) {
	            	if(resultSet.rows.item(x).testament_id == 1){
	            		$scope.bookListNewTestament.push(resultSet.rows.item(x));
	            	}else{
	            		$scope.bookListOldTestament.push(resultSet.rows.item(x));
	            	}
	            }				
			} else {
				console.log('No records found');
			}
		});

@brodycj
Copy link
Contributor

brodycj commented Jan 2, 2017

Thanks @calraiden. My understanding is that a sqlite database normally has UTF-8 or UTF-16 encoding as described in:

and a sqlite database would have UTF-8 encoding by default:

I marked this as a documentation item.

@brodycj
Copy link
Contributor

brodycj commented Mar 31, 2017

FYI I raised #652 to fix the Windows platform version to use UTF-8 encoding by default (Android/iOS/macOS platform versions already use UTF-8 encoding by default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants