答:
I would expect to see nine records in this case.  It is because there are three records with membership_id of 11 in the first table and three records of membership_id of 11 in the second table and 3*3=9 i.e. every row with membership_id of 11 in the first table is joining with every row with membership_id of 11 in the second table.

The problem here is that there is a many to many relationship between these two tables, so you need a junction.  However, do you actually need the: civicrm_membership_payment table? Can you just move contribution_id  from civicrm_membership_payment to civicrm_membershipperiod and then delete civicrm_membership_payment? Then just do:

```<code>select * from civicrm_membershipperiod
</code>```

If you cannot do this, then I would look into Junction Tables for many to many relationships.

Title: Join doesn't give correct result

Body:
I am running the below query using join. But this join doesn't give the correct result

SELECT pr.start_date,pr.end_date, p.contribution_id
FROM civicrm_membershipperiod pr
INNER JOIN civicrm_membership_payment p ON pr.membership_id=p.membership_id
where p.membership_id=11

Both tables contains three records

mysql> select *  FROM `civicrm_membershipperiod` ;
+----+---------------+------------+------------+
| id | membership_id | start_date | end_date   |
+----+---------------+------------+------------+
|  1 |            11 | 2015-01-01 | 2015-12-31 |
|  2 |            11 | 2017-07-09 | 2018-07-08 |
|  3 |            11 | 2018-07-09 | 2019-07-08 |
+----+---------------+------------+------------+
3 rows in set (0.00 sec)
--------------------------------------------------------------------------
mysql> select *  FROM `civicrm_membership_payment` ;
+----+---------------+-----------------+
| id | membership_id | contribution_id |
+----+---------------+-----------------+
| 27 |            11 |              39 |
| 28 |            11 |              40 |
| 29 |            11 |              41 |
+----+---------------+-----------------+
3 rows in set (0.00 sec)

But result is nine records instead of three records.

mysql> SELECT pr.start_date,pr.end_date, p.contribution_id FROM civicrm_membershipperiod pr INNER JOIN civicrm_membership_payment p ON pr.membership_id=p.membership_id where p.membership_id=11;
+------------+------------+-----------------+
| start_date | end_date   | contribution_id |
+------------+------------+-----------------+
| 2015-01-01 | 2015-12-31 |              39 |
| 2015-01-01 | 2015-12-31 |              40 |
| 2015-01-01 | 2015-12-31 |              41 |
| 2017-07-09 | 2018-07-08 |              39 |
| 2017-07-09 | 2018-07-08 |              40 |
| 2017-07-09 | 2018-07-08 |              41 |
| 2018-07-09 | 2019-07-08 |              39 |
| 2018-07-09 | 2019-07-08 |              40 |
| 2018-07-09 | 2019-07-08 |              41 |
+------------+------------+-----------------+
9 rows in set (0.00 sec)

I am not sure where the error is.

This is I want:

2015-01-01  2015-12-31  39
2017-07-09  2018-07-08  40
2018-07-09  2019-07-08  41

Body:
I would expect to see nine records in this case.  It is because there are three records with membership_id of 11 in the first table and three records of membership_id of 11 in the second table and 3*3=9 i.e. every row with membership_id of 11 in the first table is joining with every row with membership_id of 11 in the second table.

The problem here is that there is a many to many relationship between these two tables, so you need a junction.  However, do you actually need the: civicrm_membership_payment table? Can you just move contribution_id  from civicrm_membership_payment to civicrm_membershipperiod and then delete civicrm_membership_payment? Then just do:

select * from civicrm_membershipperiod

If you cannot do this, then I would look into Junction Tables for many to many relationships.


来源: stackexchange

问:
File.Exists + File.Move Erroring "The process cannot access the file because it is being used by another process."
I have what I thought would be a very simple file mover script. It checks for a file and moves it to a new directory if it exists:

```<code>if (File.Exists(_collection[x,0]))
{
    System.IO.File.Move(_collection[x, 0], _moveTo);
    MessageBox.Show("File moved because it was stale.");
}
</code>```

It passes the check that the file exists, but then errors on the following line when trying to move it stating that the file is being used by another process. I can only assume that File.Exists is causing it to hang up somehow, but can't find a solution from anyone else who had this problem.

答:
try this code:</p>

```<code>    string filePathNameToMove = "";
    string directoryPathToMove = "";

    if (File.Exists(filePathNameToMove))
    {
        string destinationFilePathName =
               Path.Combine(directoryPathToMove, Path.GetFileName(filePathNameToMove));
        if (!File.Exists(destinationFilePathName))
        {
            try
            {
                File.Move(filePathNameToMove, destinationFilePathName);
                Console.WriteLine("File Moved!");
            }
            catch (Exception e)
            {
                Console.WriteLine("File Not Moved! Error:" + e.Message);

            }
        }
    }
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have what I thought would be a very simple file mover script. It checks for a file and moves it to a new directory if it exists:

if (File.Exists(_collection[x,0]))
{
    System.IO.File.Move(_collection[x, 0], _moveTo);
    MessageBox.Show("File moved because it was stale.");
}

It passes the check that the file exists, but then errors on the following line when trying to move it stating that the file is being used by another process. I can only assume that File.Exists is causing it to hang up somehow, but can't find a solution from anyone else who had this problem.

Body:
try this code:

    string filePathNameToMove = "";
    string directoryPathToMove = "";

    if (File.Exists(filePathNameToMove))
    {
        string destinationFilePathName =
               Path.Combine(directoryPathToMove, Path.GetFileName(filePathNameToMove));
        if (!File.Exists(destinationFilePathName))
        {
            try
            {
                File.Move(filePathNameToMove, destinationFilePathName);
                Console.WriteLine("File Moved!");
            }
            catch (Exception e)
            {
                Console.WriteLine("File Not Moved! Error:" + e.Message);

            }
        }
    }


问:
Mongo PHP join data from another collection and update doc - like SQL JOIN
I need help with MongoDb with PHP driver.

I have 4 collections:

order_aproved :

```<code>{
   "order_id" : mongoId ,
   "user_id":num ,
   "order_date":mongoDate ,
   "requset" : string
}
</code>```

orders_rejected :

```<code>{
  "order_id" : mongoId,
  "user_id" : num ,
  "order_date" : mongoDate ,
  "requset" : string
}
</code>```

users :

```<code>{
  "user_id" : mongoId,
  "username" : num ,
  "last_order" : mongoDate ,
  "num_orders" : num,
  "last_order"
}
</code>```

orders_log :

```<code>{
   "order_id" : mongoId  ,
   "order_date" : mongoDate ,
   "status" : boolen ,
   "user_id" : num
}
</code>```

Every approved/rejected order, I update the num_orders on user document
that have a new/rejected order. So that number is always changing
and log that order on orders_log.

I need to fetch all orders approved/rejected on orders_log by list of users [array] with condition and get the orders count num_orders and last order date for that user by the order from this user

I am doing it like this:

```<code>$cursor = $orders->find()->sort(array("order_date" => -1))->limit(15);
$array = iterator_to_array($cursor,false);

$users_for_aproved = ["123","124","125"];
$users_for_rejcted = ["112","113","114"];

$js = "function() { if ( this.requset )  { return this.requset.length > 0 } }";

$query1 = array( '$and' => array(
    array("user_id" => array('$in'=> $users_for_aproved)),
    array('$where' => $js )
));

$query1 = array( '$and' => array(
    array("user_id" => array('$in'=> $users_for_rejcted)),
    array('$where' => $js )
));

$query_or = array('$or' => array($query,$query1);

$cursor = $orders_log->find($query_or)->sort(array("order_date" => -1))->limit(15);
$array = iterator_to_array($cursor,false);

for (  $x=0; $x < count($array) ; $x++ ) {

    $query = array( "user_id" => $order["user_id"] );
    $cursor = $orders->find($query)->limit(1);
    $array = iterator_to_array($cursor,false);

    $order_count = $array[0]["num_orders"];
    $array[$x]["order_count"] = $order_count;
}

return $array;
</code>```

It's working but its not very efficient , i need a way to fetch data from another collection and add the num_orders to the doc that i have find without a use form anther query

like SQL JOIN but on mongo and php driver
Thanks!

答:
There are two ways to achieve gain in performance in this case:

create an index on MongoDB:

db.order_aproved.createIndex( { user_id: 1 } )

You may create the above index either in the above way, or in the background:

db.order_aproved.createIndex( { user_id: 1 }, { background: true } )

In the last case, the creation will be slower, but it will not bother the currently ongoing operations on the database. If you may afford it, I think you should better create an index not in the background, esp. if are not running this script on the Production Database

re-design the collections, so that instead of the different collections, joined by some ID, you should create embedded documents inside the main document, thus eliminating the need to perform any operations, similar to JOINs in RDBMSs.

Of the above, simplest and more straight forward solution in your case, seems to me the first one. Choosing it, you will also avoid performance losses in updates for embedded documents

Body:
I need help with MongoDb with PHP driver.

I have 4 collections:

order_aproved :

{
   "order_id" : mongoId ,
   "user_id":num ,
   "order_date":mongoDate ,
   "requset" : string
}

orders_rejected :

{
  "order_id" : mongoId,
  "user_id" : num ,
  "order_date" : mongoDate ,
  "requset" : string
}

users :

{
  "user_id" : mongoId,
  "username" : num ,
  "last_order" : mongoDate ,
  "num_orders" : num,
  "last_order"
}

orders_log :

{
   "order_id" : mongoId  ,
   "order_date" : mongoDate ,
   "status" : boolen ,
   "user_id" : num
}

Every approved/rejected order, I update the num_orders on user document
that have a new/rejected order. So that number is always changing
and log that order on orders_log.

I need to fetch all orders approved/rejected on orders_log by list of users [array] with condition and get the orders count num_orders and last order date for that user by the order from this user

I am doing it like this:

$cursor = $orders->find()->sort(array("order_date" => -1))->limit(15);
$array = iterator_to_array($cursor,false);

$users_for_aproved = ["123","124","125"];
$users_for_rejcted = ["112","113","114"];

$js = "function() { if ( this.requset )  { return this.requset.length > 0 } }";

$query1 = array( '$and' => array(
    array("user_id" => array('$in'=> $users_for_aproved)),
    array('$where' => $js )
));

$query1 = array( '$and' => array(
    array("user_id" => array('$in'=> $users_for_rejcted)),
    array('$where' => $js )
));

$query_or = array('$or' => array($query,$query1);

$cursor = $orders_log->find($query_or)->sort(array("order_date" => -1))->limit(15);
$array = iterator_to_array($cursor,false);

for (  $x=0; $x < count($array) ; $x++ ) {

    $query = array( "user_id" => $order["user_id"] );
    $cursor = $orders->find($query)->limit(1);
    $array = iterator_to_array($cursor,false);

    $order_count = $array[0]["num_orders"];
    $array[$x]["order_count"] = $order_count;
}

return $array;

It's working but its not very efficient , i need a way to fetch data from another collection and add the num_orders to the doc that i have find without a use form anther query

like SQL JOIN but on mongo and php driver
Thanks!


问:
Garbage value retrieval
```<code>#include<stdio.h>
#include<conio.h>

int *x()
{
  int y=10;
  return (&y);
}

void main()
{
  int *p;
  clrscr();
  p=x();
  printf("%d",*p);  // Output 10
  getch();
}
</code>```

Here when we call x() function, activation record of x is pushed onto the stack. When we come out of that function, the activation record and all the local variables inside it are destroyed.
So, how are we able to access the value of y in main function after coming out of x function ? The output value should be some garbage value as "y" variable is destroyed.

答: Function x returning a pointer to an automatic local variable and causing undefined behavior. In this case any expected or unexpected result can be seen.

Title: Garbage value retrieval

Body:
#include<stdio.h>
#include<conio.h>

int *x()
{
  int y=10;
  return (&y);
}

void main()
{
  int *p;
  clrscr();
  p=x();
  printf("%d",*p);  // Output 10
  getch();
}

Here when we call x() function, activation record of x is pushed onto the stack. When we come out of that function, the activation record and all the local variables inside it are destroyed.
So, how are we able to access the value of y in main function after coming out of x function ? The output value should be some garbage value as "y" variable is destroyed.


问:
Sort a linked list changing pointer's values
Im trying to make a code to sort a linked list changin the pointers value.The program crashes when i get to the last node.The searchMinor functions works fine, the problem is in the logic of sortList.</p>

```<code>typedef struct{
    int num;
}t_dataL;

typedef struct s_nodeL{
    t_dataL dataL;
    struct s_nodeL *next;
}t_nodeL;

typedef t_nodeL *t_list;

t_list *searchMinor(t_nodeL*n){
    t_list *min=&n, *l=&n;
    l=&(*l)->next;
    while(*l) {
        if( (*l)->dataL.num < (*min)->dataL.num )min=l;
        l=&(*l)->next;
    }
    return min;
}

void sortList(t_list *l){
    t_nodeL *nbegin=*l;           //save the beginig of the list in nbegin
    t_list *plec,*aux;
    plec=searchMinor(nbegin);    //search the minor from the begining
    *l=*plec;                  //put as the first elemnet on the list the fisrt minor value
    while(nbegin->next){
        aux=&(*plec)->next;    //Save the value of the next of the minor in aux
        *plec=*aux;          //remove the minor from the list
        plec=searchMinor(nbegin); //search the new minor from the begining of the list
        *aux=*plec;         //the next of the old minor is the new minor
    }
}
</code>```

答:
You are obtaining the local copy of nbegin in sortList. Because you are returning local copy, it is the reason of undefined behaviour. Instead, you have to pass the address of it. Like,

```<code>// edit the function according to the signature
t_list *searchMinor(t_nodeL **n);

// and call like in sortList
searchMinor(&nbegin)
</code>```

Body:
Im trying to make a code to sort a linked list changin the pointers value.The program crashes when i get to the last node.The searchMinor functions works fine, the problem is in the logic of sortList.

typedef struct{
    int num;
}t_dataL;

typedef struct s_nodeL{
    t_dataL dataL;
    struct s_nodeL *next;
}t_nodeL;

typedef t_nodeL *t_list;

t_list *searchMinor(t_nodeL*n){
    t_list *min=&n, *l=&n;
    l=&(*l)->next;
    while(*l) {
        if( (*l)->dataL.num < (*min)->dataL.num )min=l;
        l=&(*l)->next;
    }
    return min;
}

void sortList(t_list *l){
    t_nodeL *nbegin=*l;           //save the beginig of the list in nbegin
    t_list *plec,*aux;
    plec=searchMinor(nbegin);    //search the minor from the begining
    *l=*plec;                  //put as the first elemnet on the list the fisrt minor value
    while(nbegin->next){
        aux=&(*plec)->next;    //Save the value of the next of the minor in aux
        *plec=*aux;          //remove the minor from the list
        plec=searchMinor(nbegin); //search the new minor from the begining of the list
        *aux=*plec;         //the next of the old minor is the new minor
    }
}

Body:
You are obtaining the local copy of nbegin in sortList. Because you are returning local copy, it is the reason of undefined behaviour. Instead, you have to pass the address of it. Like,

// edit the function according to the signature
t_list *searchMinor(t_nodeL **n);

// and call like in sortList
searchMinor(&nbegin)


答:
Is not like "y" gets destroyed.
Its memory region is labelled as "writable"

So you may either find your "y", as well as a garbage value.
After all, the function is returning a pointer, not the variable itself

Title: Garbage value retrieval


问:
How can I get OS default apps in android
I'm developing a launcher app, I need to retrieve an Android OS default Phone app, Browser app and SMS apps', application Info (Application name, Package name, Launcher icon). Following code is used to get all launchable applications.</p>

```<code>private static List<ApplicationInfo> getInstalledApps(Context context, PackageManager pm) {
    List<ApplicationInfo> installedApps = context.getPackageManager().getInstalledApplications(0);
    List<ApplicationInfo> laughableInstalledApps = new ArrayList<>();
    for(int i =0; i<installedApps.size(); i++){
        if(pm.getLaunchIntentForPackage(installedApps.get(i).packageName) != null){
            laughableInstalledApps.add(installedApps.get(i));
        }
    }
    return laughableInstalledApps;
}
</code>```

答:
Try with PackageManager#getPreferredActivities(java.util.List, java.util.List, java.lang.String), where the first parameter is a list of IntentFilter, which you would like to get default apps for. Then the answer is written in list passed as second parameter.

Here are some common intents for which you might try to find default apps.

Body:
I'm developing a launcher app, I need to retrieve an Android OS default Phone app, Browser app and SMS apps', application Info (Application name, Package name, Launcher icon). Following code is used to get all launchable applications.

private static List<ApplicationInfo> getInstalledApps(Context context, PackageManager pm) {
    List<ApplicationInfo> installedApps = context.getPackageManager().getInstalledApplications(0);
    List<ApplicationInfo> laughableInstalledApps = new ArrayList<>();
    for(int i =0; i<installedApps.size(); i++){
        if(pm.getLaunchIntentForPackage(installedApps.get(i).packageName) != null){
            laughableInstalledApps.add(installedApps.get(i));
        }
    }
    return laughableInstalledApps;
}


问:
Extract Text between HTML tags with sed or grep
I have a Problem. I want to get two parts of this html in values with the sed or grep command. How i can extract both of them?

test.html:

```<code><html>
 <body>
  <div id="foo" class="foo">
   Some Text.
    <p id="author" class="author">
     <br>
     <a href="example.com">bar</a>
    </p>
  </div>
 </body>
</html>
</code>```

script.sh

```<code>#!/bin/bash

author=$(sed 's/.*<p id="author" class="author"><br><a href="*">\(.*\)<\/a><\/p>.*/\1/p' test.html)
quote=$(sed 's/.*<div id="foo" class="foo">\(.*\)<\/div>.*/\1/p' test.html)
</code>```

Under the line i want only the text in the values. without the html tags.
But my script doesent works..

答:
The code:

```<code>text="$(sed 's:^ *::g' < test.html | tr -d \\n)"
author=$(sed 's:.*<p id="author" class="author"><br><a href="[^"]*">\([^<]*\)<.*:\1:' <<<"$text")
quote=$(sed 's:.*<div id="foo" class="foo">\([^<]*\)<.*:\1:' <<<"$text")
echo "'$author' '$quote'"
</code>```

How it works:

$text is assigned an unindented single-line representation of test.html; note that : is used as a delimiter for sed instead of /, since any character is capable of being a delimiter, and the text we are parsing has /-s present, so we don`t have to escape them with \-s when constructing a regex.

$author is assumed to be between

 (where [^"]* means «any characters except ", repeated N times, N ∈ [0, +∞)») and any tag that comes next.

$quote is assumed to be between
 and any tag that comes next.

The rather obscure construct <<<"$text" is the so-called href="http://tldp.org/LDP/abs/html/x17837.html" rel="noreferrer">here-string, which is almost equivalent to echo "$text" | placed at the beginning.

Body:
I have a Problem. I want to get two parts of this html in values with the sed or grep command. How i can extract both of them?

test.html:

   Some Text.

     bar

script.sh

#!/bin/bash

author=$(sed 's/.*

\(.*\)<\/a><\/p>.*/\1/p' test.html)
quote=$(sed 's/.*
\(.*\)<\/div>.*/\1/p' test.html)

Under the line i want only the text in the values. without the html tags.
But my script doesent works..

Body:
The code:

text="$(sed 's:^ *::g' < test.html | tr -d \\n)"
author=$(sed 's:.*<p id="author" class="author"><br><a href="[^"]*">\([^<]*\)<.*:\1:' <<<"$text")
quote=$(sed 's:.*<div id="foo" class="foo">\([^<]*\)<.*:\1:' <<<"$text")
echo "'$author' '$quote'"

How it works:

$text is assigned an unindented single-line representation of test.html; note that : is used as a delimiter for sed instead of /, since any character is capable of being a delimiter, and the text we are parsing has /-s present, so we don`t have to escape them with \-s when constructing a regex.

$author is assumed to be between <p id="author" class="author"><br><a href="[^"]*"> (where [^"]* means «any characters except ", repeated N times, N ∈ [0, +∞)») and any tag that comes next.

$quote is assumed to be between <div id="foo" class="foo"> and any tag that comes next.

The rather obscure construct <<<"$text" is the so-called here-string, which is almost equivalent to echo "$text" | placed at the beginning.


问:
Can hibernate first level caching be disabled?
Can hibernate first level caching be disabled?

Incase it can't be disabled, are there any work arounds?

答:
Hibernate first level cache is associated with the Session object.
Hibernate first level cache is enabled by default and there is no way to disable it.
 However hibernate provides methods through which we can delete selected objects from the cache or clear the cache completely.
Any object cached in a session will not be visible to other sessions and when the session is closed, all the cached objects will also be lost.</p>


问:
Objective-c how to Synchronize iphone apps for develop other source or website data
how to Synchronize  iphone apps for develop other source or website data

anyone can ask me thanks

please send me some link,or tutorial or demo ,example,script  (http://status.net/wiki/Building_StatusNet_Mobile_from_source)

i am use mac os to edit xcode

i'm use open source to handle iphone of that part

jackie chan

答:
You need to redo your question. What are you trying to do? </p>

<p>It sounds like you are trying to sync code between computers. In which case google SVN and GIT. </p>

ContentLicense: CC BY-SA 2.5

Body:
You need to redo your question. What are you trying to do?

It sounds like you are trying to sync code between computers. In which case google SVN and GIT.


答:
Local variables have a limited lifetime which only extends inside the block {} they are defined. They have a local-scope.

When the control reaches the end of the block all the storage for the variables in it is not guaranteed  to not be writable.

That portion of memory can be re-used. Will it be? who knows.

This translates to: undefined behaviour!

Title: Garbage value retrieval


答:
The result is absolutely correct according to what you have written.
The membership_id of each tuple in both tables civicrm_membershipperiod and civicrm_membership_payment is 11.
As each tuple of civicrm_membershipperiod is matched against each tuple of the other table on the column membership_id, it finds no mismatches. Due to this, it yields 3*3=9 matches.</p>

Title: Join doesn't give correct result


问:
Static member access in constant expressions
Accessing static class member functions or variables, can be done in two ways: through an object (obj.member_fun() or obj.member_var) or through the class (Class::member_fun() or Class::member_var). However, in constexpr functions, Clang gives an error on the object access and requires to use class access:

```<code>struct S
{
    constexpr static auto s_v = 42;
    constexpr static auto v() { return s_v; }
};

#define TEST 1

constexpr auto foo(S const& s [[maybe_unused]])
{
#if TEST
    constexpr auto v = s.v();   // ERROR for clang, OK for gcc
#else
    constexpr auto v = S::v();  // OK for clang and gcc
#endif
    return v;
}

constexpr auto bar(S const& s [[maybe_unused]])
{
#if TEST
    constexpr auto v = s.s_v;   // ERROR for clang, OK for gcc
#else
    constexpr auto v = S::s_v;  // OK for clang and gcc
#endif
    return v;
}

int main() {}
</code>```

Live Example compiled with -std=c++1z and #define TEST 1 for Clang 5.0 SVN, with error message:

```<code>Start
prog.cc:12:24: error: constexpr variable 'v' must be initialized by a constant expression
    constexpr auto v = s.v();   // ERROR for clang, OK for gcc
                       ^~~~~
prog.cc:22:24: error: constexpr variable 'v' must be initialized by a constant expression
    constexpr auto v = s.s_v;   // ERROR for clang, OK for gcc
                       ^~~~~
2 errors generated.
1
Finish
</code>```

Question: is this is a Clang bug, or is gcc too liberal in accepting both syntax forms for static member access in a constexpr function?

答:
```<code>constexpr auto v = s.v();   // ERROR for clang, OK for gcc
</code>```

I guess it depends on whether you compile in C++11 or C++14 mode. If you look over at cppreference, you will find (emphasis added by me):

A core constant expression is any expression that does not have any one of the following

  (...)

  6) The this pointer, except if used for class member access inside a non-static member function (until C++14)

  6) The this pointer, except in a constexpr function or a constexpr constructor that is being evaluated as part of the expression (since C++14)

So, in C++11, whatever happens inside s.v() would not be considered a constant expression, since it uses the this pointer, but it is not a non-static member function (it's static) accessing a class member.

Per C++14, however, it would be, since it is evaluating a constexpr function as part of the expression, so the "except if" clause on the "does not have any of" set of rules catches.

Now don't ask me whether that makes any sense or whether anyone is supposed to understand that... :-)

Body:
Accessing static class member functions or variables, can be done in two ways: through an object (obj.member_fun() or obj.member_var) or through the class (Class::member_fun() or Class::member_var). However, in constexpr functions, Clang gives an error on the object access and requires to use class access:

struct S
{
    constexpr static auto s_v = 42;
    constexpr static auto v() { return s_v; }
};

#define TEST 1

constexpr auto foo(S const& s [[maybe_unused]])
{
#if TEST
    constexpr auto v = s.v();   // ERROR for clang, OK for gcc
#else
    constexpr auto v = S::v();  // OK for clang and gcc
#endif
    return v;
}

constexpr auto bar(S const& s [[maybe_unused]])
{
#if TEST
    constexpr auto v = s.s_v;   // ERROR for clang, OK for gcc
#else
    constexpr auto v = S::s_v;  // OK for clang and gcc
#endif
    return v;
}

int main() {}

Live Example compiled with -std=c++1z and #define TEST 1 for Clang 5.0 SVN, with error message:

Start
prog.cc:12:24: error: constexpr variable 'v' must be initialized by a constant expression
    constexpr auto v = s.v();   // ERROR for clang, OK for gcc
                       ^~~~~
prog.cc:22:24: error: constexpr variable 'v' must be initialized by a constant expression
    constexpr auto v = s.s_v;   // ERROR for clang, OK for gcc
                       ^~~~~
2 errors generated.
1
Finish

Question: is this is a Clang bug, or is gcc too liberal in accepting both syntax forms for static member access in a constexpr function?

Body:
constexpr auto v = s.v();   // ERROR for clang, OK for gcc

I guess it depends on whether you compile in C++11 or C++14 mode. If you look over at cppreference, you will find (emphasis added by me):

A core constant expression is any expression that does not have any one of the following

  (...)

  6) The this pointer, except if used for class member access inside a non-static member function (until C++14)

  6) The this pointer, except in a constexpr function or a constexpr constructor that is being evaluated as part of the expression (since C++14)

So, in C++11, whatever happens inside s.v() would not be considered a constant expression, since it uses the this pointer, but it is not a non-static member function (it's static) accessing a class member.

Per C++14, however, it would be, since it is evaluating a constexpr function as part of the expression, so the "except if" clause on the "does not have any of" set of rules catches.

Now don't ask me whether that makes any sense or whether anyone is supposed to understand that... :-)


问:
gotoxy() function substitute for Dev C not working
I was looking for a substitute of gotoxy for Dev C++ v5.11 (gcc compiler) and found this:

```<code>void gotoxy(int x,int y) {
    printf("%c[%d;%df", 0x1b, y, x);
}
</code>```

After this when I tried to call this function as follows:

```<code>int main() {
    gotoxy(20, 10);
    printf("Hello");
    return 0;
}
</code>```

Output was not as expected:

```<code><-[10;20fHello
</code>```

This was printed in top left most corner of screen (i.e. 1,1)
instead of (20,10).

Please give me suggestions that what I can do to use gotoxy in my code.

答:
Your ANSI escape sequence is incorrect, it should be \033[%d;%dH, but it seems your terminal does not support ANSI VT100 escape sequences at all. In Windows, there might be a configuration setting to enable it, VT100 emulation is standard in most modern operating systems terminals (unix, linux, BSD, OS/X...).

Here is the modified code:

```<code>#include <stdio.h>

void gotoxy(int x, int y) {
    printf("\033[%d;%dH", y, x);
}

int main(void) {
    gotoxy(20, 10);
    printf("Hello\n");
    return 0;
}
</code>```

Body:
I was looking for a substitute of gotoxy for Dev C++ v5.11 (gcc compiler) and found this:

void gotoxy(int x,int y) {
    printf("%c[%d;%df", 0x1b, y, x);
}

After this when I tried to call this function as follows:

int main() {
    gotoxy(20, 10);
    printf("Hello");
    return 0;
}

Output was not as expected:

<-[10;20fHello

This was printed in top left most corner of screen (i.e. 1,1)
instead of (20,10).

Please give me suggestions that what I can do to use gotoxy in my code.

Body:
Your ANSI escape sequence is incorrect, it should be \033[%d;%dH, but it seems your terminal does not support ANSI VT100 escape sequences at all. In Windows, there might be a configuration setting to enable it, VT100 emulation is standard in most modern operating systems terminals (unix, linux, BSD, OS/X...).

Here is the modified code:

#include <stdio.h>

void gotoxy(int x, int y) {
    printf("\033[%d;%dH", y, x);
}

int main(void) {
    gotoxy(20, 10);
    printf("Hello\n");
    return 0;
}


问:
Using patern attribute in html
I want to use the pattern attribute to allow only UPPERCASE LETTERS, NUMBERS AND FORWARD SLASH. (A-Z, 0-9,/).
How do do I achieve this </p>

答:
use regex:

```<code>([A-Z][A-Z0-9][- /.])\w+
</code>```

it allows upper case ,numbers,and /. thanks.

Title: Using patern attribute in html

Body:
use regex:

([A-Z][A-Z0-9][- /.])\w+

it allows upper case ,numbers,and /. thanks.


问:
Angular 2 WYSWYG form builder
I am looking for a Form builder that i can use in my angular 2 application.

I found many form builders built in angular 1.x but couldn't find one for angular 2.

here is the list of those which i found.

Form.io

AngularJs form builder

Schema form

Kelp 404 Angular form builder

Need help if there is any form builder for angular 2 +

答: Try https://form.io/ It supports angular 2 framework</p>

Title: Angular 2 WYSWYG form builder


问:
Pentaho Error - ConnectionServiceImpl.ERROR_0009 - Connection to database [null] failed
I'm trying to setup pentaho connection with MySQL server(localhost). However, this error "ConnectionServiceImpl.ERROR_0009 - Connection to database [null] failed" appears when i try testing the connection. The information about server should be right.
Information Picture:

[i've no password for root account in MySQL] and MySQL connector file have been insered in the pentaho server lib folder.

Connector Folder Picture:

I've looked for log file and i found this about my connection test:

```<code>2017-07-08 17:12:02,915 ERROR [org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl] Error Start: Pentaho pentaho-platform-core 7.1.0.0-12
2017-07-08 17:12:02,915 ERROR [org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl] ::: Can't get connection from Pool
org.pentaho.platform.api.data.DBDatasourceServiceException: java.lang.RuntimeException: PooledDatasourceHelper.ERROR_0009 - Unable to pool Data Source [ Data_Warehouse_Incidenti ]. Cannot initialize org.gjt.mm.mysql.Driver.
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.setupPooledDataSource(PooledDatasourceHelper.java:319)
    at org.pentaho.platform.plugin.services.connections.sql.SQLConnection.initDataSource(SQLConnection.java:581)
    at org.pentaho.platform.plugin.services.connections.sql.SQLConnection.connect(SQLConnection.java:597)
    at org.pentaho.platform.plugin.services.connections.sql.SQLConnection.setProperties(SQLConnection.java:108)
    at org.pentaho.platform.engine.services.connection.PentahoConnectionFactory.getConnection(PentahoConnectionFactory.java:124)
    at org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl.testConnection(ConnectionServiceImpl.java:323)
    at org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionService.testConnection(ConnectionService.java:240)
    at sun.reflect.GeneratedMethodAccessor367.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    at org.pentaho.platform.web.servlet.JAXRSPluginServlet.service(JAXRSPluginServlet.java:112)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.pentaho.platform.web.servlet.JAXRSPluginServlet.service(JAXRSPluginServlet.java:117)
    at org.pentaho.platform.web.servlet.PluginDispatchServlet.service(PluginDispatchServlet.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.PentahoWebContextFilter.doFilter(PentahoWebContextFilter.java:195)
    at com.pentaho.platform.web.http.filters.PentahoEnterpriseWebContextFilter.doFilter(SourceFile:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.PentahoRequestContextFilter.doFilter(PentahoRequestContextFilter.java:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.pentaho.platform.web.http.security.RequestParameterAuthenticationFilter.doFilter(RequestParameterAuthenticationFilter.java:191)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
    at org.pentaho.platform.web.http.security.PentahoBasicProcessingFilter.doFilterInternal(PentahoBasicProcessingFilter.java:125)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.pentaho.platform.web.http.filters.HttpSessionPentahoSessionIntegrationFilter.doFilter(HttpSessionPentahoSessionIntegrationFilter.java:271)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at com.pentaho.ui.servlet.SystemStatusFilter.doFilter(SourceFile:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:114)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.WebappRootForwardingFilter.doFilter(WebappRootForwardingFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.PentahoPathDecodingFilter.doFilter(PentahoPathDecodingFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2521)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2510)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: PooledDatasourceHelper.ERROR_0009 - Unable to pool Data Source [ Data_Warehouse_Incidenti ]. Cannot initialize org.gjt.mm.mysql.Driver.
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.setupPooledDataSource(PooledDatasourceHelper.java:167)
    ... 96 more
2017-07-08 17:12:02,917 ERROR [org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl] Error end:
</code>```

I've looked for many solution but I haven't found anything. What's missing about it?

答:
There a few things here:

Is your MySQL server running on localhost? Is it running on port 3306?

Are you sure this is the correct connection you are showing? In the log it says Cannot initialize org.gjt.mm.mysql.Driver (the old version), but in the connection window you have provided com.mysql.jdbc.Driver (the new version). Why the difference=

This looks to me that you are using the wrong driver class. Is the connection defined elsewhere?

EDIT

First result for "pentaho driver jars directory" is this page. It states that external jars have to go into the directory

```<code>pentaho/jdbc-distribution
</code>```

Afterwards a file has to be executed

```<code>distribute-files.bat <name of JDBC driver JAR>
</code>```

Then restart the server. Also, there is a list of folders for the applications you use.

Body:
I'm trying to setup pentaho connection with MySQL server(localhost). However, this error "ConnectionServiceImpl.ERROR_0009 - Connection to database [null] failed" appears when i try testing the connection. The information about server should be right.
Information Picture:

[i've no password for root account in MySQL] and MySQL connector file have been insered in the pentaho server lib folder.

Connector Folder Picture:

I've looked for log file and i found this about my connection test:

2017-07-08 17:12:02,915 ERROR [org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl] Error Start: Pentaho pentaho-platform-core 7.1.0.0-12
2017-07-08 17:12:02,915 ERROR [org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl] ::: Can't get connection from Pool
org.pentaho.platform.api.data.DBDatasourceServiceException: java.lang.RuntimeException: PooledDatasourceHelper.ERROR_0009 - Unable to pool Data Source [ Data_Warehouse_Incidenti ]. Cannot initialize org.gjt.mm.mysql.Driver.
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.setupPooledDataSource(PooledDatasourceHelper.java:319)
    at org.pentaho.platform.plugin.services.connections.sql.SQLConnection.initDataSource(SQLConnection.java:581)
    at org.pentaho.platform.plugin.services.connections.sql.SQLConnection.connect(SQLConnection.java:597)
    at org.pentaho.platform.plugin.services.connections.sql.SQLConnection.setProperties(SQLConnection.java:108)
    at org.pentaho.platform.engine.services.connection.PentahoConnectionFactory.getConnection(PentahoConnectionFactory.java:124)
    at org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl.testConnection(ConnectionServiceImpl.java:323)
    at org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionService.testConnection(ConnectionService.java:240)
    at sun.reflect.GeneratedMethodAccessor367.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
    at org.pentaho.platform.web.servlet.JAXRSPluginServlet.service(JAXRSPluginServlet.java:112)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.pentaho.platform.web.servlet.JAXRSPluginServlet.service(JAXRSPluginServlet.java:117)
    at org.pentaho.platform.web.servlet.PluginDispatchServlet.service(PluginDispatchServlet.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.PentahoWebContextFilter.doFilter(PentahoWebContextFilter.java:195)
    at com.pentaho.platform.web.http.filters.PentahoEnterpriseWebContextFilter.doFilter(SourceFile:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.PentahoRequestContextFilter.doFilter(PentahoRequestContextFilter.java:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.pentaho.platform.web.http.security.RequestParameterAuthenticationFilter.doFilter(RequestParameterAuthenticationFilter.java:191)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
    at org.pentaho.platform.web.http.security.PentahoBasicProcessingFilter.doFilterInternal(PentahoBasicProcessingFilter.java:125)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.pentaho.platform.web.http.filters.HttpSessionPentahoSessionIntegrationFilter.doFilter(HttpSessionPentahoSessionIntegrationFilter.java:271)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at com.pentaho.ui.servlet.SystemStatusFilter.doFilter(SourceFile:87)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:114)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.WebappRootForwardingFilter.doFilter(WebappRootForwardingFilter.java:70)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.pentaho.platform.web.http.filters.PentahoPathDecodingFilter.doFilter(PentahoPathDecodingFilter.java:34)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2521)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2510)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: PooledDatasourceHelper.ERROR_0009 - Unable to pool Data Source [ Data_Warehouse_Incidenti ]. Cannot initialize org.gjt.mm.mysql.Driver.
    at org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceHelper.setupPooledDataSource(PooledDatasourceHelper.java:167)
    ... 96 more
2017-07-08 17:12:02,917 ERROR [org.pentaho.platform.dataaccess.datasource.wizard.service.impl.ConnectionServiceImpl] Error end:

I've looked for many solution but I haven't found anything. What's missing about it?

Body:
There a few things here:

Is your MySQL server running on localhost? Is it running on port 3306?

Are you sure this is the correct connection you are showing? In the log it says Cannot initialize org.gjt.mm.mysql.Driver (the old version), but in the connection window you have provided com.mysql.jdbc.Driver (the new version). Why the difference=

This looks to me that you are using the wrong driver class. Is the connection defined elsewhere?

EDIT

First result for "pentaho driver jars directory" is this page. It states that external jars have to go into the directory

pentaho/jdbc-distribution

Afterwards a file has to be executed

distribute-files.bat <name of JDBC driver JAR>

Then restart the server. Also, there is a list of folders for the applications you use.


问:
Can't get auto layout to make two buttons side by side stay there
I'm at the point where I'm going crazy, I've tried everything to get these two buttons to stay where they are even if the device is changed. Any help at all would be amazing, this has been driving me crazy for hours.

答:
Insert those buttons into horizontal StackView component (which is available in iOS 9 and later) and set alignment to fill. Setup their constraints to have aspect ration on themselves and setup them to have equal width (at least that)... Much simpler approach IMO

see:

https://www.raywenderlich.com/114552/uistackview-tutorial-introducing-stack-views


问:
how to get query string of kendo datasource
I am using kendo grid to which data is provided by kendo data source. I am using quite a complicated filter and thats why I have to use parameterMap function to do some sorting and filtering. When the query is sent, the query string is automatically prepared by the data source and everything works fine. I need a way to store this url (at least the query string) for every read request. Is there a way to access it?</p>

答:
After some research... that was pretty easy. It is enough to use decodeURIComponent before returning data in the parameterMap function:</p>

```<code> parameterMap: function (data, operation) {
     ...
     storeSomewhereTheValueOf(decodeURIComponent($.param(data)));
     return data;
}
</code>```

Body:
After some research... that was pretty easy. It is enough to use decodeURIComponent before returning data in the parameterMap function:

 parameterMap: function (data, operation) {
     ...
     storeSomewhereTheValueOf(decodeURIComponent($.param(data)));
     return data;
}


问:
Fill a DataGridView according to the selected row of the parent's one
I have 2 DataGridView controls, I have to fill the second one according to the idGarantie of the selected row of my first dataGridView

Here is the First DGV where I show the Garanties

```<code>        var queryGaranties = from g in serviceGaranties.Liste()
            join t in serviceTauxCotisation.Liste() on g.idGarantie equals t.idGarantie
            select new {g.idGarantie, g.libelGarantie, t.tauxA, t.tauxB};

        GridGaranties.DataSource = queryGaranties.ToList();
        GridGaranties.DataBind();
</code>```

Here is the second one :

```<code>    protected void GridGaranties_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        var queryClauses = from c in serviceClauses.Liste()
            join g in serviceGaranties.Liste() on c.idGarantie equals g.idGarantie
            join n in serviceNiveauGaranties.Liste() on c.idClause equals n.idClause
            where c.idGarantie == **// find idGarantie on selected row of GridGaranties**
            select new {c.idClause, c.libelClause, n.TauxCouvA, n.TauxCouvB};

        GridClauses.DataSource = queryClauses.ToList();
        GridClauses.DataBind();
    }
</code>```

can I use the DataKeyNames with or should I take the value of the cell in the selected row ?

Thank you

答:
First, store relevant values of GridGaranties in RowDataBound

```<code>protected void GridGaranties_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       DataRowView rowView = (DataRowView)e.Row.DataItem;
       e.Row.Attributes.Add("idGarantie", (int)rowView["idGarantie"].ToString());
    }
}
</code>```

Then read back your attribute in SelectedIndexChanged

```<code>protected void GridGaranties_OnSelectedIndexChanged(object sender, EventArgs e)
{
   var selectedRow = GridGaranties.SelectedRow;
   int idGarantie = Int32.Parse(selectedRow.Attributes["idGarantie"]);

   //Now you can perform your query
}
</code>```

Hope that it helps

Body:
I have 2 DataGridView controls, I have to fill the second one according to the idGarantie of the selected row of my first dataGridView

Here is the First DGV where I show the Garanties

        var queryGaranties = from g in serviceGaranties.Liste()
            join t in serviceTauxCotisation.Liste() on g.idGarantie equals t.idGarantie
            select new {g.idGarantie, g.libelGarantie, t.tauxA, t.tauxB};

        GridGaranties.DataSource = queryGaranties.ToList();
        GridGaranties.DataBind();

Here is the second one :

    protected void GridGaranties_OnSelectedIndexChanged(object sender, EventArgs e)
    {
        var queryClauses = from c in serviceClauses.Liste()
            join g in serviceGaranties.Liste() on c.idGarantie equals g.idGarantie
            join n in serviceNiveauGaranties.Liste() on c.idClause equals n.idClause
            where c.idGarantie == **// find idGarantie on selected row of GridGaranties**
            select new {c.idClause, c.libelClause, n.TauxCouvA, n.TauxCouvB};

        GridClauses.DataSource = queryClauses.ToList();
        GridClauses.DataBind();
    }

can I use the DataKeyNames with or should I take the value of the cell in the selected row ?

Thank you

Body:
First, store relevant values of GridGaranties in RowDataBound

protected void GridGaranties_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
       DataRowView rowView = (DataRowView)e.Row.DataItem;
       e.Row.Attributes.Add("idGarantie", (int)rowView["idGarantie"].ToString());
    }
}

Then read back your attribute in SelectedIndexChanged

protected void GridGaranties_OnSelectedIndexChanged(object sender, EventArgs e)
{
   var selectedRow = GridGaranties.SelectedRow;
   int idGarantie = Int32.Parse(selectedRow.Attributes["idGarantie"]);

   //Now you can perform your query
}

Hope that it helps


问:
C recursive program to find the maximum element from array
So I have a task in my training that sounds like this:
Write a subprogram that will recursively find the maximum element from an array and also write the main function to call it.
What I failed to fully understand is what recursion is. I wanted to ask you guys if my code is recursive or not. And if not what changes should I make/ what recursion really means?

```<code>#include <stdio.h>

int find_maximum(int[], int);

int main() {
  int c, array[100], size, location, maximum;

  printf("Input number of elements in array\n");
  scanf("%d", &size);

  printf("Enter %d integers\n", size);

  for (c = 0; c < size; c++)
    scanf("%d", &array[c]);

  location = find_maximum(array, size);
  maximum  = array[location];

  printf("Maximum element location = %d and value = %d.\n", location + 1, maximum);
  return 0;
}

int find_maximum(int a[], int n) {
  int c, max, index;

  max = a[0];
  index = 0;

  for (c = 1; c < n; c++) {
    if (a[c] > max) {
       index = c;
       max = a[c];
    }
  }

  return index;
}
</code>```

Thank you all for your time!

答:
Think of calculating the maximum number in an array as the number which will be maximum of the first element and the maximum of the remaining elements of the array. Something like: max(first_elem, max(remaining_elems)).

The actual recursive function: find_max quite simple, if there is just a single element in the array, that element is returned. Otherwise, we get the maximum of the first element and the remaining elements of the array.

```<code>#include <stdio.h>

// function to find the max of 2 numbers
int max(int x, int y)
{
    return (x > y) ? x : y;
}

// the recursive function
int find_max(int *p, int n)
{
    if (n == 1) return *p;

    return max(*p, find_max(p + 1, n - 1));
}

int main(void)
{
    int arr[] = {23, 3, 11, -98, 99, 45};
    printf("max: %d\n", find_max(arr, sizeof arr / sizeof arr[0]));
}
</code>```

Body:
So I have a task in my training that sounds like this:
Write a subprogram that will recursively find the maximum element from an array and also write the main function to call it.
What I failed to fully understand is what recursion is. I wanted to ask you guys if my code is recursive or not. And if not what changes should I make/ what recursion really means?

#include <stdio.h>

int find_maximum(int[], int);

int main() {
  int c, array[100], size, location, maximum;

  printf("Input number of elements in array\n");
  scanf("%d", &size);

  printf("Enter %d integers\n", size);

  for (c = 0; c < size; c++)
    scanf("%d", &array[c]);

  location = find_maximum(array, size);
  maximum  = array[location];

  printf("Maximum element location = %d and value = %d.\n", location + 1, maximum);
  return 0;
}

int find_maximum(int a[], int n) {
  int c, max, index;

  max = a[0];
  index = 0;

  for (c = 1; c < n; c++) {
    if (a[c] > max) {
       index = c;
       max = a[c];
    }
  }

  return index;
}

Thank you all for your time!

Body:
Think of calculating the maximum number in an array as the number which will be maximum of the first element and the maximum of the remaining elements of the array. Something like: max(first_elem, max(remaining_elems)).

The actual recursive function: find_max quite simple, if there is just a single element in the array, that element is returned. Otherwise, we get the maximum of the first element and the remaining elements of the array.

#include <stdio.h>

// function to find the max of 2 numbers
int max(int x, int y)
{
    return (x > y) ? x : y;
}

// the recursive function
int find_max(int *p, int n)
{
    if (n == 1) return *p;

    return max(*p, find_max(p + 1, n - 1));
}

int main(void)
{
    int arr[] = {23, 3, 11, -98, 99, 45};
    printf("max: %d\n", find_max(arr, sizeof arr / sizeof arr[0]));
}


问:
Get an specific file from an specific folder
Hi Im doing a Windows 8 Javascript App, y what to know how to get a file witch name is example2.dat from C:\Users\Me\Pictures\thifolder I tried using Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder");
but it didnt work since i have another files like example1.dat, example3.dat example.jpg etc.

Hope i made my self clear, thanks in advance

Here is my code so far

```<code>    function here() {
        var getJsonStringAsync = function () {

            return   Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder")
//Also tried this
            //return Windows.Storage.KnownFolders.picturesLibrary.getFileAsync(u_u + "_" + u + "_" + ".dat")
                    .then(function (file) {
                        return Windows.Storage.FileIO.readTextAsync(file);
                    });
        };

        getJsonStringAsync().then(function (text) {
        document.getElementById("line").innerHTML = text;
    });
}
</code>```

答:
In JavaScript, here is how to play "song.mp3" which is in the music library:

Html:

```<code>  <audio id="player1">Your browser does not support audio </audio>
</code>```

JavaScript:

```<code>        var ml = Windows.Storage.KnownFolders.musicLibrary;
            ml.getFileAsync("song.mp3").then(function (file) {
                // its a storage file, so create URL from it
                var s = window.URL.createObjectURL(file);
                player1.setAttribute("src", s);
                player1.play();
            //});
        });
</code>```

Body:
Hi Im doing a Windows 8 Javascript App, y what to know how to get a file witch name is example2.dat from C:\Users\Me\Pictures\thifolder I tried using Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder");
but it didnt work since i have another files like example1.dat, example3.dat example.jpg etc.

Hope i made my self clear, thanks in advance

Here is my code so far

    function here() {
        var getJsonStringAsync = function () {

            return   Windows.Storage.StorageFile.getFileFromPathAsync("C:\Users\Me\Pictures\thisfolder")
//Also tried this
            //return Windows.Storage.KnownFolders.picturesLibrary.getFileAsync(u_u + "_" + u + "_" + ".dat")
                    .then(function (file) {
                        return Windows.Storage.FileIO.readTextAsync(file);
                    });
        };

        getJsonStringAsync().then(function (text) {
        document.getElementById("line").innerHTML = text;
    });
}

Body:
In JavaScript, here is how to play "song.mp3" which is in the music library:

Html:

  <audio id="player1">Your browser does not support audio </audio>

JavaScript:

        var ml = Windows.Storage.KnownFolders.musicLibrary;
            ml.getFileAsync("song.mp3").then(function (file) {
                // its a storage file, so create URL from it
                var s = window.URL.createObjectURL(file);
                player1.setAttribute("src", s);
                player1.play();
            //});
        });


问:
Store MSMQ queue in database
I'm new to MSMQ for .NET and have a question.

For my system I want to use MSMQ for queuing some system requests, but a customer wants to keep all information in database. I wonder is there any way to store MSMQ messages in database?

Currently I see the only way to create some record in database and put record id to queue.

答: If you'd like to keep in all "close" to the database then have a look at the SQL Server Service Broker.  This is messaging done within SQL Server.</p>

Title: Store MSMQ queue in database


问:
Is it possible to find out if some list is fixed size or not?
Is it possible to find out if some a list is fixed size or not?
I mean, for example this code:

```<code>String[] arr = {"a", "b"};
List<String> list = Arrays.asList(array);
</code>```

returns fixed size List backed by an array. But is it possible to understand programmatically if List is fixed-size or not without trying to add/remove elements and catching the exception? For example:

```<code>try {
    list.add("c");
}
catch(UnsupportedOperationException e) {
    // Fixed-size?
}
</code>```

答:
There are immutable collections in java-9, but there is still no common @Immutable annotation for example or a common marker interface that we could query to get this information.

The simplest way I can think of would be simply to get the name of the class of such an instance:

```<code>String nameList = List.of(1, 2, 3).getClass().getName();
System.out.println(nameList.contains("Immutable"));
</code>```

but that still relies on internal details, since it queries the name of the common class ImmutableCollections, that is not public and obviously can change without notice.

Body:
Is it possible to find out if some a list is fixed size or not?
I mean, for example this code:

String[] arr = {"a", "b"};
List<String> list = Arrays.asList(array);

returns fixed size List backed by an array. But is it possible to understand programmatically if List is fixed-size or not without trying to add/remove elements and catching the exception? For example:

try {
    list.add("c");
}
catch(UnsupportedOperationException e) {
    // Fixed-size?
}

Body:
There are immutable collections in java-9, but there is still no common @Immutable annotation for example or a common marker interface that we could query to get this information.

The simplest way I can think of would be simply to get the name of the class of such an instance:

String nameList = List.of(1, 2, 3).getClass().getName();
System.out.println(nameList.contains("Immutable"));

but that still relies on internal details, since it queries the name of the common class ImmutableCollections, that is not public and obviously can change without notice.


问:
How to Calculate sum of data in php?

In this table I have multiple value like CGST, SGST, NET AMOUNT, MRP I want to find total of all value in below given CGST, SGCST etc...

Please help me how to find total of all data.

This is the code:

```<code><table class="table table-striped">
                        <thead>
                            <tr>
                                <th><strong>Sr. No</strong></th>
                                <th><strong>Item Name</strong></th>
                                <th><strong>Serial No</strong></th>
                                <th><strong>CGST</strong></th>
                                <th><strong>SGST</strong></th>
                                <th><strong>NET AMOUNT</strong></th>
                                <th><strong>MRP</strong></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                                $counter = 0;

                                    $getData = mysql_query("SELECT CUSTOMER_ID, ITEM_ID, DATE, FLAG, GROUP_CONCAT(SERIAL_NO) AS SERIAL_NO FROM cart_mst WHERE CUSTOMER_ID = '".$_SESSION['cust']."' AND FLAG = '0' GROUP BY ITEM_ID");

                                    while($row = mysql_fetch_array($getData))
                                    {
                                        $getItem = mysql_query("SELECT * FROM item_details WHERE ITEM_ID = '".$row['ITEM_ID']."'");
                                        $rowItem = mysql_fetch_array($getItem);

                            ?>

                            <tr>
                                <td><?php echo ++$counter ?></td>
                                <td>
                                    <?php echo $rowItem['ITEM_NAME'];

                                        $schools_array = explode(",", $row['SERIAL_NO']);
                                        $qty = count($schools_array);
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        $hobbies = explode(',', $row['SERIAL_NO']);
                                        foreach ($hobbies as $hobby)
                                        {
                                            // output each hobby and decorate/separate them however you'd like
                                            echo $hobby . ', ';
                                        }
                                    ?>
                                </td>

                                <td>
                                    <?php
                                        if($rowItem['TYPE'] == "BAT")
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/128;
                                            $cgst = $net_amt * 14/100;
                                            echo round($cgst, 2);
                                        }
                                        else
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/118;
                                            $cgst = $net_amt * 9/100;
                                            echo round($cgst, 2);
                                        }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        if($rowItem['TYPE'] == "BAT")
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/128;
                                            $sgst = $net_amt * 14/100;
                                            echo round($cgst, 2);
                                        }
                                        else
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/118;
                                            $cgst = $net_amt * 9/100;
                                            echo round($cgst, 2);
                                        }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        if($rowItem['TYPE'] =="BAT")
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/128;
                                            echo round($net_amt, 2);
                                        }
                                        else
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/118;
                                            echo round($net_amt, 2);
                                        }
                                    ?>
                                </td>
                                <td>
                                    <?php
                                        $a = $rowItem['MRP'];
                                        $tot = $a * $qty;
                                        echo $tot;
                                    ?>
                                </td>
                            </tr>

                            <?php
                                    }

                            ?>
                        </tbody>
                    </table>
</code>```

答:
```<code>This is simple first you initalize your variable as 0.
$cgst=0;
$sgst=0;
$netAmount=0;
$totalAmount=0;
In loop
$cgst=$cgst+Your Cgst Amount of current row;
$sgst=$sgst+Your Sgst Amount of current row;
$netAmount=$netAmount+Your Net Amount of current row;
$totalAmount=$totalAmount+Your Total Amount of current row;
</code>```

Title: How to Calculate sum of data in php?

Body:
In this table I have multiple value like CGST, SGST, NET AMOUNT, MRP I want to find total of all value in below given CGST, SGCST etc...

Please help me how to find total of all data.

This is the code:

                                Sr. No
                                Item Name
                                Serial No
                                CGST
                                SGST
                                NET AMOUNT
                                MRP

                            <?php
                                $counter = 0;

                                    $getData = mysql_query("SELECT CUSTOMER_ID, ITEM_ID, DATE, FLAG, GROUP_CONCAT(SERIAL_NO) AS SERIAL_NO FROM cart_mst WHERE CUSTOMER_ID = '".$_SESSION['cust']."' AND FLAG = '0' GROUP BY ITEM_ID");

                                    while($row = mysql_fetch_array($getData))
                                    {
                                        $getItem = mysql_query("SELECT * FROM item_details WHERE ITEM_ID = '".$row['ITEM_ID']."'");
                                        $rowItem = mysql_fetch_array($getItem);

                            ?>

                                <?php echo ++$counter ?>

                                    <?php echo $rowItem['ITEM_NAME'];

                                        $schools_array = explode(",", $row['SERIAL_NO']);
                                        $qty = count($schools_array);
                                    ?>

                                    <?php
                                        $hobbies = explode(',', $row['SERIAL_NO']);
                                        foreach ($hobbies as $hobby)
                                        {
                                            // output each hobby and decorate/separate them however you'd like
                                            echo $hobby . ', ';
                                        }
                                    ?>

                                    <?php
                                        if($rowItem['TYPE'] == "BAT")
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/128;
                                            $cgst = $net_amt * 14/100;
                                            echo round($cgst, 2);
                                        }
                                        else
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/118;
                                            $cgst = $net_amt * 9/100;
                                            echo round($cgst, 2);
                                        }
                                    ?>

                                    <?php
                                        if($rowItem['TYPE'] == "BAT")
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/128;
                                            $sgst = $net_amt * 14/100;
                                            echo round($cgst, 2);
                                        }
                                        else
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/118;
                                            $cgst = $net_amt * 9/100;
                                            echo round($cgst, 2);
                                        }
                                    ?>

                                    <?php
                                        if($rowItem['TYPE'] =="BAT")
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/128;
                                            echo round($net_amt, 2);
                                        }
                                        else
                                        {
                                            $mrp = $rowItem['MRP'];
                                            $tot = $mrp * $qty;
                                            $net_amt = $tot * 100/118;
                                            echo round($net_amt, 2);
                                        }
                                    ?>

                                    <?php
                                        $a = $rowItem['MRP'];
                                        $tot = $a * $qty;
                                        echo $tot;
                                    ?>

                            <?php
                                    }

                            ?>


问:
Pulling a dynamic key value from a JSON array search result query
I use Wikipedia API to search for Wiki articles. When I click the submit button I get an Array in JSON as a result :

```<code>0 {ns: 0, title: "Help", size: 3677, wordcount: 433, snippet: "<span class=\"searchmatch\">Help</span> is any form …mmand-line shells that invokes documentations and", …}

1 {ns: 0, title: "Online help", size: 7326, wordcount: 380, snippet: "(HTML), which includes HTML <span class=\"searchmat…earchmatch\">help</span> is also provided via live", …}

2 {ns: 0, title: "Help desk", size: 9491, wordcount: 1296, snippet: "A <span class=\"searchmatch\">help</span> desk is a …ated to a company's or institution's products and", …}

...
</code>```

I need to pull the value of the title and use it inside the HTML in a results list and at the same time put it inside the url so the user can click on a result and go to the corresponding page. (url:http://../[title])

The array is located in data.query.search

Since the results are dynamic I would probably need some kind of a for loop that will iterate through this array no matter how many results there are. I have tried with this for loop but it doesn't work.

```<code>console.log(data.query.search); //shows array in console
          data.query.search =""; //the location of JSON array
 for (i = 0; i < data.query.search["results"].length; i++) {
  data.query.search["results"][i]["title"];
  console.log("results");
}
</code>```

I suspect that I am not targeting the array elements,keys and values properly. I am grateful for any suggestion. Cheers.

答:
var data = { query: { search: [
  {ns: 0, title: "Help", size: 3677, wordcount: 433},
  {ns: 0, title: "Online help", size: 7326, wordcount: 380},
  {ns: 0, title: "Help desk", size: 9491, wordcount: 1296}
]}};

var  titleArray = data.query.search.map(function(arrObj) {
  return arrObj.title;
})

  console.log(titleArray);```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script></code>```

Body:
I use Wikipedia API to search for Wiki articles. When I click the submit button I get an Array in JSON as a result :

0 {ns: 0, title: "Help", size: 3677, wordcount: 433, snippet: "Help is any form …mmand-line shells that invokes documentations and", …}

1 {ns: 0, title: "Online help", size: 7326, wordcount: 380, snippet: "(HTML), which includes HTML help is also provided via live", …}

2 {ns: 0, title: "Help desk", size: 9491, wordcount: 1296, snippet: "A help desk is a …ated to a company's or institution's products and", …}

...

I need to pull the value of the title and use it inside the HTML in a results list and at the same time put it inside the url so the user can click on a result and go to the corresponding page. (url:http://../[title])

The array is located in data.query.search

Since the results are dynamic I would probably need some kind of a for loop that will iterate through this array no matter how many results there are. I have tried with this for loop but it doesn't work.

console.log(data.query.search); //shows array in console
          data.query.search =""; //the location of JSON array
 for (i = 0; i < data.query.search["results"].length; i++) {
  data.query.search["results"][i]["title"];
  console.log("results");
}

I suspect that I am not targeting the array elements,keys and values properly. I am grateful for any suggestion. Cheers.

Body:
var data = { query: { search: [
  {ns: 0, title: "Help", size: 3677, wordcount: 433},
  {ns: 0, title: "Online help", size: 7326, wordcount: 380},
  {ns: 0, title: "Help desk", size: 9491, wordcount: 1296}
]}};

var  titleArray = data.query.search.map(function(arrObj) {
  return arrObj.title;
})

  console.log(titleArray);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>


问:
Change UISearchBar Shap
I used UISearchBar in the project, but I can't change the view of it. I want to set border around the search bar.

Can I change UIsearchbar as the same as this image?

答: You can set invisible searchbar with transparent borders and background and below that just add image/draw subview if the shape you want. I think Adding UIView with property explicitly: layer.cornerRadius = 4.0 should work :) </p>

Title: Change UISearchBar Shap


答:
This is the expected behaviour, given your data. You are JOINing your two tables using membership_id. However, each row in civicrm_membership_payment with membership_id = 11 matches three records on the other table. Thats why you have 3 x 3 = 9 rows in your result.

This looks like a design flaw, your table civicrm_membership_payment should have a reference that allows it to decide to which period this payment refers to.

dbfiddle here for your current situation.

Alternative: change the definition of your tables to account for that:

```<code>CREATE TABLE civicrm_membershipperiod
(
    /* no need for a synthetic id, surrogate primary key */
    membership_id INTEGER,
    start_date date,
    end_date date,
    PRIMARY KEY (membership_id, start_date),  /* "Natural" PK */
    CHECK (end_date >= start_date)
) ;

INSERT INTO civicrm_membershipperiod
    (membership_id, start_date, end_date)
VALUES
    (11, '2015-01-01', '2015-12-31'),
    (11, '2017-07-09', '2018-07-08'),
    (11, '2018-07-09', '2019-07-08') ;

CREATE TABLE civicrm_membership_payment
(
    contribution_id INTEGER PRIMARY KEY,  /* Surrogate key, not really necessary */
    membership_id   INTEGER NOT NULL,
    start_date      date NOT NULL,

    CONSTRAINT fk_civicrm_membershipperiod_civicrm_membershipperiod
        FOREIGN KEY (membership_id, start_date)
        REFERENCES civicrm_membershipperiod(membership_id, start_date)
) ;

INSERT INTO civicrm_membership_payment
    (membership_id, contribution_id, start_date)
VALUES
    (11, 39, '2015-01-01'),
    (11, 40, '2017-07-09'),
    (11, 41, '2018-07-09') ;

SELECT
    pr.start_date,pr.end_date, p.contribution_id
FROM
    civicrm_membershipperiod pr
    INNER JOIN civicrm_membership_payment p
        ON p.membership_id = pr.membership_id AND p.start_date = pr.start_date
WHERE
    p.membership_id=11
</code>```

```
start_date | end_date   | contribution_id
:--------- | :--------- | --------------:
2015-01-01 | 2015-12-31 |              39
2017-07-09 | 2018-07-08 |              40
2018-07-09 | 2019-07-08 |              41
```

dbfiddle here

NOTE: You don't need to have an AUTO_INCREMENT id for every table. They might be convenient in some occasions, but you can also use natural primary keys (a column or combination of columns that will let you uniquely identify rows in your table, and that has some meaning). I've used them instead of the synthetic PK where I thought they would better represent the problem at hand.

Title: Join doesn't give correct result

Body:
I am running the below query using join. But this join doesn't give the correct result

SELECT pr.start_date,pr.end_date, p.contribution_id
FROM civicrm_membershipperiod pr
INNER JOIN civicrm_membership_payment p ON pr.membership_id=p.membership_id
where p.membership_id=11

Both tables contains three records

mysql> select *  FROM `civicrm_membershipperiod` ;
+----+---------------+------------+------------+
| id | membership_id | start_date | end_date   |
+----+---------------+------------+------------+
|  1 |            11 | 2015-01-01 | 2015-12-31 |
|  2 |            11 | 2017-07-09 | 2018-07-08 |
|  3 |            11 | 2018-07-09 | 2019-07-08 |
+----+---------------+------------+------------+
3 rows in set (0.00 sec)
--------------------------------------------------------------------------
mysql> select *  FROM `civicrm_membership_payment` ;
+----+---------------+-----------------+
| id | membership_id | contribution_id |
+----+---------------+-----------------+
| 27 |            11 |              39 |
| 28 |            11 |              40 |
| 29 |            11 |              41 |
+----+---------------+-----------------+
3 rows in set (0.00 sec)

But result is nine records instead of three records.

mysql> SELECT pr.start_date,pr.end_date, p.contribution_id FROM civicrm_membershipperiod pr INNER JOIN civicrm_membership_payment p ON pr.membership_id=p.membership_id where p.membership_id=11;
+------------+------------+-----------------+
| start_date | end_date   | contribution_id |
+------------+------------+-----------------+
| 2015-01-01 | 2015-12-31 |              39 |
| 2015-01-01 | 2015-12-31 |              40 |
| 2015-01-01 | 2015-12-31 |              41 |
| 2017-07-09 | 2018-07-08 |              39 |
| 2017-07-09 | 2018-07-08 |              40 |
| 2017-07-09 | 2018-07-08 |              41 |
| 2018-07-09 | 2019-07-08 |              39 |
| 2018-07-09 | 2019-07-08 |              40 |
| 2018-07-09 | 2019-07-08 |              41 |
+------------+------------+-----------------+
9 rows in set (0.00 sec)

I am not sure where the error is.

This is I want:

2015-01-01  2015-12-31  39
2017-07-09  2018-07-08  40
2018-07-09  2019-07-08  41

Body:
This is the expected behaviour, given your data. You are JOINing your two tables using membership_id. However, each row in civicrm_membership_payment with membership_id = 11 matches three records on the other table. Thats why you have 3 x 3 = 9 rows in your result.

This looks like a design flaw, your table civicrm_membership_payment should have a reference that allows it to decide to which period this payment refers to.

dbfiddle here for your current situation.

Alternative: change the definition of your tables to account for that:

CREATE TABLE civicrm_membershipperiod
(
    /* no need for a synthetic id, surrogate primary key */
    membership_id INTEGER,
    start_date date,
    end_date date,
    PRIMARY KEY (membership_id, start_date),  /* "Natural" PK */
    CHECK (end_date >= start_date)
) ;

INSERT INTO civicrm_membershipperiod
    (membership_id, start_date, end_date)
VALUES
    (11, '2015-01-01', '2015-12-31'),
    (11, '2017-07-09', '2018-07-08'),
    (11, '2018-07-09', '2019-07-08') ;

CREATE TABLE civicrm_membership_payment
(
    contribution_id INTEGER PRIMARY KEY,  /* Surrogate key, not really necessary */
    membership_id   INTEGER NOT NULL,
    start_date      date NOT NULL,

    CONSTRAINT fk_civicrm_membershipperiod_civicrm_membershipperiod
        FOREIGN KEY (membership_id, start_date)
        REFERENCES civicrm_membershipperiod(membership_id, start_date)
) ;

INSERT INTO civicrm_membership_payment
    (membership_id, contribution_id, start_date)
VALUES
    (11, 39, '2015-01-01'),
    (11, 40, '2017-07-09'),
    (11, 41, '2018-07-09') ;

SELECT
    pr.start_date,pr.end_date, p.contribution_id
FROM
    civicrm_membershipperiod pr
    INNER JOIN civicrm_membership_payment p
        ON p.membership_id = pr.membership_id AND p.start_date = pr.start_date
WHERE
    p.membership_id=11

start_date | end_date   | contribution_id
:--------- | :--------- | --------------:
2015-01-01 | 2015-12-31 |              39
2017-07-09 | 2018-07-08 |              40
2018-07-09 | 2019-07-08 |              41

dbfiddle here

NOTE: You don't need to have an AUTO_INCREMENT id for every table. They might be convenient in some occasions, but you can also use natural primary keys (a column or combination of columns that will let you uniquely identify rows in your table, and that has some meaning). I've used them instead of the synthetic PK where I thought they would better represent the problem at hand.


问:
User defined command
I am having a situation for which I am looking for some suggestion.

Suppose I write a program which prints the directory names of the directories.
Is it possible to convert this program into a command (just on my system).
Not be alias but via C only.

答:
First, compile the program and create an executable using gcc program.c -o myexecfile. Then, an executable file named myexecfile is created in the same directory. You can run it by using ./myexecfile.

If you are on Unix(Linux etc.) and want to use it like ls or any other standard command, you need to place it in a directory that is specified in $PATH variable. For example, /usr/local/bin.

Title: User defined command


问:
What is the best/safest way to reinstall Homebrew?
I am getting issues with permissions in Homebrew: After I installed Node and tried to install npm using the curl command Homebrew tells you to use, it would fail due to EACCESS errors. I checked the node folder and the permissions were a) unowned by a user (I had to chown it) and b) Had no write permissions (I had to chmod 755 it).

I've fixed the issue with NPM, but I had to run its install script as sudo (which is bad!).

I assume I must have installed Homebrew as root or something similar. I am hoping that reinstallation will fix it, but I can't find a source on how to reinstall Homebrew.

When I rerun the installer in Terminal I get:

```<code>/usr/local/.git already exists!
</code>```

答:
For me, this one worked without the sudo access.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

For more reference, please follow
https://gist.github.com/mxcl/323731

Body:
I am getting issues with permissions in Homebrew: After I installed Node and tried to install npm using the curl command Homebrew tells you to use, it would fail due to EACCESS errors. I checked the node folder and the permissions were a) unowned by a user (I had to chown it) and b) Had no write permissions (I had to chmod 755 it).

I've fixed the issue with NPM, but I had to run its install script as sudo (which is bad!).

I assume I must have installed Homebrew as root or something similar. I am hoping that reinstallation will fix it, but I can't find a source on how to reinstall Homebrew.

When I rerun the installer in Terminal I get:

/usr/local/.git already exists!


答:
Yes you can definitely change the appearance of UISearchbar to the image displayed.

Basically you will need to customise the properties of UISearchBar and associated UITextField and modify the visibility of the search button.

I found "the" article which will help you to achieve the desired result.

http://en.codecloud.net/989.html

Hope this helps.

Title: Change UISearchBar Shap

Body:
I used UISearchBar in the project, but I can't change the view of it. I want to set border around the search bar.

Can I change UIsearchbar as the same as this image?