Assistance with DUB

2016-11-01 Thread Alfred Newman via Digitalmars-d-learn

Greetings,

I need some help with dub libraries.

Executing "dub list" in my machine, I got the following:

Packages present in the system and known to dub:
colorize ~master: 
C:\Users\Alfred\AppData\Roaming\dub\packages\colorize-master\colorize\

...
sqlite-d ~master: 
C:\Users\Alfred\AppData\Roaming\dub\packages\sqlite-d-master\sqlite-d\
x11 1.0.15: 
C:\Users\Alfred\AppData\Roaming\dub\packages\x11-1.0.15\x11\


*** Note that sqlite-d is listed there.

When I try to run the code in the end of this thread, I got the 
following error:


compiling C:...\Projects\temp2.d
C:\Users\Alfred\Dropbox\Dlang\Projects\temp2.d(8,8): Error: 
module sqlited is in file 'sqlited.d' which cannot be read (***)

import path[0] = C:\D\dmd2\src\phobos
import path[1] = C:\D\dmd2\src\druntime\import
import path[2] = 
C:\Users\Alfred\AppData\Roaming\dub\packages\colorize-master\colorize\source
import path[3] = 
C:\Users\Alfred\AppData\Roaming\dub\packages\sqlite-d-master\sqlite-d
import path[4] = 
C:\Users\Alfred\AppData\Roaming\dub\packages\d2sqlite3-master\d2sqlite3\source

import path[5] = C:\D\dmd2\windows\bin\src\phobos
import path[6] = C:\D\dmd2\windows\bin\src\druntime\import
error: the process (dmd) has returned the signal 1
C:...\Projects\temp2.d has not been compiled

I'm stucked. Please, can you help me out ?

Cheers, AN


module test;

//  Copyright Stefan Koch 2015 - 2018.
// Distributed under the Boost Software License, Version 1.0.
//(See accompanying file LICENSE.md or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

import sqlited;
import misc;
import sqlstuff;

static immutable long_create_table =
q{CREATE TABLE `hey`INTEGER,
`Field2`INTEGER
)};
static immutable test_s3db = 
cast(immutable)Database(cast(immutable ubyte[]) 
import("test.s3db"));
static immutable Database.MasterTableSchema[] schemas = 
readRows!(r => 
r.deserialize!(Database.MasterTableSchema))(test_s3db.rootPage, 
test_s3db.pages);

static assert(schemas[2].sql==long_create_table);

import frail_sql_parser;

static assert (parseCreateTable(
q{CREATE TABLE spatial_ref_sys (
srid INTEGER NOT NULL PRIMARY KEY,
auth_name VARCHAR(256) NOT NULL,
auth_srid INTEGER NOT NULL,
ref_sys_name VARCHAR(256),
proj4text VARCHAR(2048) NOT NULL)}
) == TableInfo("spatial_ref_sys", [
ColumInfo("srid", "INTEGER", true, true),
ColumInfo("auth_name", "VARCHAR(256)", false, true),
ColumInfo("auth_srid", "INTEGER", false, true),
ColumInfo("ref_sys_name","VARCHAR(256)",false),
ColumInfo("proj4text","VARCHAR(2048)", false, true),
])
);
static assert(parseCreateTable(long_create_table) == 
TableInfo("hey", "INTEGER"), ColumInfo("Field2", "INTEGER")]));


static assert(parseCreateTable(
q{CREATE TABLE Towns (
PK_UID INTEGER PRIMARY KEY AUTOINCREMENT,
Name TEXT,
Peoples INTEGER,
LocalCounc INTEGER,
County INTEGER,
Region INTEGER, "Geometry" POINT)
}
) == TableInfo("Towns", [
ColumInfo("PK_UID", "INTEGER", true, false, false, true),
ColumInfo("Name", "TEXT"),
ColumInfo("Peoples", "INTEGER"),
ColumInfo("LocalCounc", "INTEGER"),
ColumInfo("County", "INTEGER"),
ColumInfo("Region", "INTEGER"),
ColumInfo("Geometry", "POINT")
])
);


Re: SQLite

2016-11-01 Thread Alfred Newman via Digitalmars-d-learn

On Friday, 21 October 2016 at 10:50:30 UTC, Vadim Lopatin wrote:
On Wednesday, 19 October 2016 at 16:01:37 UTC, Alfred Newman 
wrote:

Hello,

I am trying to handle a SQLite3 table with D. During my 
researchs, I discovered the lib 
https://dlang.org/phobos/etc_c_sqlite3.html.


However, for any reason, there is no code snippets or sample 
codes available there. So, I am stucked.


I have the following sample structure table:
   sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );";

Can you pls provide a code snippet or some hints to the 
following job:

- Create a table with the layout above
- Iterate through the records given a basic SELECT WHERE Query

Thanks in advance, AN


Snippet how to do it using DDBC library 
https://github.com/buggins/ddbc


import ddbc;

string url = "sqlite:testdb.sqlite";
// creating Connection
auto conn = createConnection(url);
scope(exit) conn.close();
// creating Statement
auto stmt = conn.createStatement();
scope(exit) stmt.close();
// execute simple queries to create and fill table
stmt.executeUpdate("CREATE TABLE COMPANY (ID int, NAME 
varchar, AGE int,ADDRESS varchar, SALARY double)");

string[] statements = [
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) 
VALUES (1, 'Paul', 32, 'California', 2.00 )",
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) 
VALUES (2, 'Allen', 25, 'Texas', 15000.00 )",
"INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) 
VALUES (3, 'Teddy', 23, 'Norway', 2.00 )"

];
foreach(sql; statements)
stmt.executeUpdate(sql);


Hello Vadim,

I used dub to register DDBC. After that, I tried to do some 
tests, but I received the following error:


Fetching ddbc ~master...
Placing ddbc ~master to 
C:\Users\Alfred\AppData\Roaming\dub\packages\...

Performing "release" build using dmd for x86.
ddbc ~master: building configuration "full"...
Copying files for ddbc...

compiling C:\...\Projects\stingray.d

OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
sqlite3.lib
 Warning 2: File Not Found sqlite3.lib
C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\lib\ddbc.lib(mysqlddbc)
 Error 42: Symbol Undefined _D5mysql10connection12__ModuleInfoZ
C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\lib\ddbc.lib(pgsqlddbc)
 Error 42: Symbol Undefined _D8derelict2pq2pq12__ModuleInfoZ
C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\lib\ddbc.lib(sqliteddbc)
 Error 42: Symbol Undefined _sqlite3_data_count
...
_D5mysql8protocol8commands7Command11__xopEqualsFKxS5mysql8protocol8commands7CommandKxS5mysql8protocol8commands7CommandZb
--- errorlevel 67
error: the process (dmd) has returned the signal 67
C:\...\Projects\stingray.d has not been compiled

Notice that sqlite3.lib is located at my folder 
C:\Users\Alfred\AppData\Roaming\dub\packages\ddbc-master\ddbc\libs\win64


What am I doing wrong ?

Cheers


Re: Newbie: can't manage some types...

2016-10-31 Thread Alfred Newman via Digitalmars-d-learn
On Monday, 31 October 2016 at 11:44:25 UTC, Cleverson Casarin 
Uliana wrote:
Hello all, I'm trying to do two tasks which involves some type 
conversion, and I'm having dificulties, probably because I 
haven't yet understood well how such types works.


First, I wanted to convert UTF-8 strings to ansi, so it displays
correctly at the Windows command prompt. One function to do 
that is

"toMBSz" from std.windows.charset, which is declared as follows:
const(char)* toMBSz(in char[] s, uint codePage = 0);

So, after some struggling, I managed to write the following 
code:


import std.stdio;
import std.windows.charset;
void main() {
string s = "Testando acentuação";
auto r = toMBSz (s, 1);
writeln (r[0..19]);
}

Although the above code works, I have an impression that it 
could be more elegant and concise, but don't know how to 
improve it...


I'd also like to play a sound file, so tried to use the 
function "PlaySound" from core.sys.windows.mmsystem, declared 
as follows: BOOL PlaySoundW(LPCWSTR, HMODULE, DWORD);


According to some error messages I receive, the first parameter 
is of
type const(char)*, which corresponds to the sound file name, 
but I
just can't figure out how to convert the string (or a char 
array) to
that type... Could you please give some snippet example? The 
closest I

have come, which doesn't compile at all, is as follows:
import core.sys.windows.mmsystem;

void main() {
char[] f = "C:/base/portavox/som/_fon102.wav".dup;
const(wchar)* arq = cast(const(wchar)*)
void* nulo;
uint SND_FILENAME;
PlaySound (arq, nulo, SND_FILENAME);
}

Thank you,
Cleverson


Cleverson,

About your question related to "Testando acentuação", and 
assuming you're using Windows, you can also do the following:


import std.stdio, std.string;

//A Windows function to set the code page of the console output
extern (Windows): private int SetConsoleOutputCP(uint codepage);

void main()
{
SetConsoleOutputCP(65001);
string s = "Testando acentuação";
writeln("Output: ", s.toUpper());
}

Cheers



Re: Parse a String given some delimiters

2016-10-30 Thread Alfred Newman via Digitalmars-d-learn

On Sunday, 30 October 2016 at 23:47:54 UTC, Ali Çehreli wrote:

On 10/30/2016 01:50 PM, Alfred Newman wrote:

[...]


Here is something along the lines of what others have suggested:

auto parse(R, S)(R range, S separators) {
import std.algorithm : splitter, filter, canFind;
import std.range : empty;

[...]


Thank you @all.

@Ali, that's exactly what I was looking for.
The phobos is awesome (and pretty huge).

Cheers



Parse a String given some delimiters

2016-10-30 Thread Alfred Newman via Digitalmars-d-learn

Hello,

I'm migrating some Python code to D, but I stuck at a dead end...

Sorry to provide some .py lines over here, but I got some doubts 
about the best (fastest) way to do that in D.


Executing the function parsertoken("_My   input.string", " _,.", 
2) will result "input".

Parsercount("Dlang=-rocks!", " =-") will result 2,

def parsertoken(istring, idelimiters, iposition):
"""
Return a specific token of a given input string,
considering its position and the provided delimiters

:param istring: raw input string
:param idelimiteres: delimiters to split the tokens
:param iposition: position of the token
:return: token
"""
	vlist=''.join([s if s not in idelimiters else ' ' for s in 
istring]).split()

return vlist[vposition]

def parsercount(istring, idelimiters):
"""
Return the number of tokens at the input string
considering the delimiters provided

:param istring: raw input string
:param idelimiteres: delimiters to split the tokens
:return: a list with all the tokens found
"""
	vlist=''.join([s if s not in vdelimiters else ' ' for s in 
istring]).split()

return len(vlist)-1


Thanks in advance


Re: Best approach to handle accented letters

2016-10-28 Thread Alfred Newman via Digitalmars-d-learn

On Friday, 28 October 2016 at 15:08:59 UTC, Chris wrote:

On Friday, 28 October 2016 at 14:31:47 UTC, Chris wrote:

[...]


What you basically do is you pass the logic on to `map` and 
`map` applies it to each item in the range (cf. [1]):


[...]


The life is beautiful !
Thx.


Re: Best approach to handle accented letters

2016-10-28 Thread Alfred Newman via Digitalmars-d-learn

On Friday, 28 October 2016 at 11:40:37 UTC, Chris wrote:

On Friday, 28 October 2016 at 11:24:28 UTC, Alfred Newman wrote:

Hello,

I'm getting some troubles to replace the accented letters in a 
given string with their unaccented counterparts.


Let's say I have the following input string "très élégant" and 
I need to create a function to return just "tres elegant". 
Considering we need to take care about unicode chars, what is 
the best way to write a D code to handle that ?


Cheers


You could try something like this. It works for accents. I 
haven't tested it on other characters yet.


import std.stdio;
import std.algorithm;
import std.array;
import std.conv;

enum
{
  dchar[dchar] _accent = ['á':'a', 'é':'e', 'è':'e', 'í':'i', 
'ó':'o', 'ú':'u', 'Á':'A', 'É':'E', 'Í':'I', 'Ó':'O', 'Ú':'U']

}

void main()
{
  auto str = "très élégant";
  auto removed = to!string(str.map!(a => (a in _accent) ? 
_accent[a] : a));

  writeln(removed);  // prints "tres elegant"
}


@Chris

As a new guy in the D community, I am not sure, but I think the 
line below is something like a Python's lambda, right ?


auto removed = to!string(str.map!(a => (a in _accent) ? 
_accent[a] : a));


Can you please rewrite the line in a more didatic way ? Sorry, 
but I'm still learning the basics.


Thanks in advance


Best approach to handle accented letters

2016-10-28 Thread Alfred Newman via Digitalmars-d-learn

Hello,

I'm getting some troubles to replace the accented letters in a 
given string with their unaccented counterparts.


Let's say I have the following input string "très élégant" and I 
need to create a function to return just "tres elegant". 
Considering we need to take care about unicode chars, what is the 
best way to write a D code to handle that ?


Cheers


SQLite

2016-10-19 Thread Alfred Newman via Digitalmars-d-learn

Hello,

I am trying to handle a SQLite3 table with D. During my 
researchs, I discovered the lib 
https://dlang.org/phobos/etc_c_sqlite3.html.


However, for any reason, there is no code snippets or sample 
codes available there. So, I am stucked.


I have the following sample structure table:
   sql = "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (1, 'Paul', 32, 'California', 2.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) "  \
 "VALUES (2, 'Allen', 25, 'Texas', 15000.00 ); " \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (3, 'Teddy', 23, 'Norway', 2.00 );" \
 "INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY)" \
 "VALUES (4, 'Mark', 25, 'Rich-Mond ', 65000.00 );";

Can you pls provide a code snippet or some hints to the following 
job:

- Create a table with the layout above
- Iterate through the records given a basic SELECT WHERE Query

Thanks in advance, AN


Re: From Python to Dlang

2016-10-18 Thread Alfred Newman via Digitalmars-d-learn

@All, thanks a lot !


From Python to Dlang

2016-10-18 Thread Alfred Newman via Digitalmars-d-learn

Hello and greetings,

I'm a brand new D developer coming from Python.

I decided to move to D, mainly because it's a compiled language 
and has a great runtime speed (and I don't feel confortable 
at Cython environment at all). And of course, D has a nice 
community and the language has nice syntax too... and is a joy to 
code with.


However, I have some important production code in Python to 
migrate to D and every help will count !


So, can you pls guys suggest me any resource like "D for a Python 
Developer" or so ? BTW, I just ordered the "D Programming 
Language" book from AA.


Cheers